diff --git a/AzureTableStorageNLogTarget.1.0.9.nupkg b/AzureTableStorageNLogTarget.1.0.9.nupkg deleted file mode 100644 index 4777054..0000000 Binary files a/AzureTableStorageNLogTarget.1.0.9.nupkg and /dev/null differ diff --git a/NLog.Extensions.AzureTableStorage.EmptyApplication/.gitignore b/NLog.Extensions.AzureTableStorage.EmptyApplication/.gitignore new file mode 100644 index 0000000..97e402e --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.EmptyApplication/.gitignore @@ -0,0 +1,206 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +bower_components/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt diff --git a/NLog.Extensions.AzureTableStorage.EmptyApplication/NLog.Extensions.AzureTableStorage.EmptyApplication.xproj b/NLog.Extensions.AzureTableStorage.EmptyApplication/NLog.Extensions.AzureTableStorage.EmptyApplication.xproj new file mode 100644 index 0000000..98bef58 --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.EmptyApplication/NLog.Extensions.AzureTableStorage.EmptyApplication.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 87d6bdf5-8313-45be-90ce-d0f8f15c44a9 + EmptyApplication + ..\artifacts\obj\$(MSBuildProjectName) + ..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + \ No newline at end of file diff --git a/NLog.Extensions.AzureTableStorage.EmptyApplication/NLog.config b/NLog.Extensions.AzureTableStorage.EmptyApplication/NLog.config new file mode 100644 index 0000000..da83444 --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.EmptyApplication/NLog.config @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + diff --git a/NLog.Extensions.AzureTableStorage.EmptyApplication/Properties/launchSettings.json b/NLog.Extensions.AzureTableStorage.EmptyApplication/Properties/launchSettings.json new file mode 100644 index 0000000..da290f9 --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.EmptyApplication/Properties/launchSettings.json @@ -0,0 +1,25 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:56012/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "Hosting:Environment": "Development" + } + }, + "web": { + "commandName": "web", + "environmentVariables": { + "Hosting:Environment": "Development" + } + } + } +} \ No newline at end of file diff --git a/NLog.Extensions.AzureTableStorage.EmptyApplication/Startup.cs b/NLog.Extensions.AzureTableStorage.EmptyApplication/Startup.cs new file mode 100644 index 0000000..dd71e1a --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.EmptyApplication/Startup.cs @@ -0,0 +1,61 @@ + +using System.IO; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; +using Microsoft.Dnx.Runtime; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.PlatformAbstractions; + +namespace NLog.Extensions.AzureTableStorage.EmptyApplication +{ + public class Startup + { + private Microsoft.Extensions.Logging.ILogger _log; + private string logConfigurationFile = string.Empty; + + public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) + { + // Setup configuration sources. + + var builder = new ConfigurationBuilder() + .SetBasePath(appEnv.ApplicationBasePath) + .AddJsonFile("appsettings.json") + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); + logConfigurationFile = Path.Combine(appEnv.ApplicationBasePath, "NLog.config"); + + builder.AddEnvironmentVariables(); + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; set; } + + public void ConfigureServices(IServiceCollection services) + { + // Configure AtsOption for NLog.Extensions.AzureTableStorage + services.ConfigureAts(options => { + options.StorageAccountConnectionString = Configuration["AppSettings:StorageAccountConnectionString"]; + }); + } + + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + { + // add NLog for logging + loggerFactory.AddNLog(new LogFactory(new NLog.Config.XmlLoggingConfiguration(logConfigurationFile))); + _log = loggerFactory.CreateLogger(); + + // generate some log output + _log.LogInformation("Happy table logging!"); + _log.LogInformation(string.Format("Log configuration: {0}", logConfigurationFile)); + + app.UseIISPlatformHandler(); + + app.Run(async (context) => + { + await context.Response.WriteAsync("Hello World!"); + }); + } + } +} diff --git a/NLog.Extensions.AzureTableStorage.EmptyApplication/appsettings.json b/NLog.Extensions.AzureTableStorage.EmptyApplication/appsettings.json new file mode 100644 index 0000000..74ddae3 --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.EmptyApplication/appsettings.json @@ -0,0 +1,5 @@ +{ + "AppSettings": { + "StorageAccountConnectionString": "UseDevelopmentStorage=true" + } +} diff --git a/NLog.Extensions.AzureTableStorage.EmptyApplication/project.json b/NLog.Extensions.AzureTableStorage.EmptyApplication/project.json new file mode 100644 index 0000000..b237ada --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.EmptyApplication/project.json @@ -0,0 +1,37 @@ +{ + "version": "1.0.0-*", + "authors": [ "greenliff.com" ], + + "tooling": { + "defaultNamespace": "NLog.Extensions.AzureTableStorage.EmptyApplication" + }, + + "dependencies": { + "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final-*", + "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final-*", + "Microsoft.AspNet.Hosting": "1.0.0-rc1-final-*", + "Microsoft.Dnx.Runtime": "1.0.0-rc1-final-*", + "Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final-*", + "Microsoft.Extensions.Logging.NLog": "1.0.0-rc1-final-*", + "NLog.Extensions.AzureTableStorage": "" + }, + + "commands": { + "kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:5004", + "ef": "EntityFramework.Commands", + "web": "Microsoft.AspNet.Server.Kestrel" + }, + + "frameworks": { + "dnx451": { } + }, + + "exclude": [ + "wwwroot", + "node_modules" + ], + "publishExclude": [ + "**.user", + "**.vspscc" + ] +} diff --git a/NLog.Extensions.AzureTableStorage.EmptyApplication/wwwroot/web.config b/NLog.Extensions.AzureTableStorage.EmptyApplication/wwwroot/web.config new file mode 100644 index 0000000..e70a777 --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.EmptyApplication/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/NLog.Extensions.AzureTableStorage.Tests/App.config b/NLog.Extensions.AzureTableStorage.Tests/App.config deleted file mode 100644 index dab5818..0000000 --- a/NLog.Extensions.AzureTableStorage.Tests/App.config +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/NLog.Extensions.AzureTableStorage.Tests/AzureTableStorageTargetTests.cs b/NLog.Extensions.AzureTableStorage.Tests/AzureTableStorageTargetTests.cs index dc546ff..27ef59e 100644 --- a/NLog.Extensions.AzureTableStorage.Tests/AzureTableStorageTargetTests.cs +++ b/NLog.Extensions.AzureTableStorage.Tests/AzureTableStorageTargetTests.cs @@ -1,44 +1,75 @@ using Microsoft.Azure; +using Microsoft.Extensions.Configuration; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Table; using System; using System.Collections.Generic; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using Xunit; namespace NLog.Extensions.AzureTableStorage.Tests { + public static class Extensions + { + public static async Task> ExecuteQueryAsync(this CloudTable table, TableQuery query, CancellationToken ct = default(CancellationToken), Action> onProgress = null) where T : ITableEntity, new() + { + var items = new List(); + TableContinuationToken token = null; + + do + { + TableQuerySegment seg = await table.ExecuteQuerySegmentedAsync(query, token); + token = seg.ContinuationToken; + items.AddRange(seg); + if (onProgress != null) onProgress(items); + + } while (token != null && !ct.IsCancellationRequested); + + return items; + } + } + public class AzureTableStorageTargetTests : IDisposable { private readonly Logger _logger; private readonly CloudTable _cloudTable; private const string TargetTableName = "TempAzureTableStorageTargetTestsLogs"; //must match table name in AzureTableStorage target in NLog.config + public void SetupAction(AtsOptions options) + { + var cb = new ConfigurationBuilder().AddJsonFile("appsettings.json"); + IConfigurationRoot config = cb.Build(); + options.StorageAccountConnectionString = config["AppSettings:StorageAccountConnectionString"]; + } + public AzureTableStorageTargetTests() { try { - _logger = LogManager.GetLogger(GetType().ToString()); + AtsCoreServiceCollectionExtensions.ConfigureAts(null, SetupAction); + LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration("NLog.config"); + _logger = LogManager.GetCurrentClassLogger(); var storageAccount = GetStorageAccount(); // Create the table client. var tableClient = storageAccount.CreateCloudTableClient(); //create charts table if not exists. _cloudTable = tableClient.GetTableReference(TargetTableName); - _cloudTable.CreateIfNotExists(); + _cloudTable.CreateIfNotExistsAsync().Wait(); } catch (Exception ex) { throw new Exception("Failed to initialize tests, make sure Azure Storage Emulator is running.", ex); } - } [Fact] - public void CanLogInformation() + public async Task CanLogInformation() { - Assert.True(GetLogEntities().Count == 0); + Assert.True((await GetLogEntities()).Count == 0); _logger.Log(LogLevel.Info, "information"); - var entities = GetLogEntities(); + var entities = await GetLogEntities(); var entity = entities.Single(); Assert.True(entities.Count == 1); Assert.Equal("information", entity.Message); @@ -47,11 +78,11 @@ public void CanLogInformation() } [Fact] - public void CanLogExceptions() + public async Task CanLogExceptions() { - Assert.True(GetLogEntities().Count == 0); - _logger.Log(LogLevel.Error, "exception message", (Exception)new NullReferenceException()); - var entities = GetLogEntities(); + Assert.True((await GetLogEntities()).Count == 0); + _logger.Log(LogLevel.Error, new NullReferenceException(), "exception message"); + var entities = await GetLogEntities(); var entity = entities.Single(); Assert.True(entities.Count == 1); Assert.Equal("exception message", entity.Message); @@ -61,45 +92,43 @@ public void CanLogExceptions() } [Fact] - public void IncludeExceptionFormattedMessengerInLoggedRow() + public async Task IncludeExceptionFormattedMessengerInLoggedRow() { _logger.Debug("exception message {0} and {1}.", 2010, 2014); - var entity = GetLogEntities().Single(); + var entity = (await GetLogEntities()).Single(); Assert.Equal("exception message 2010 and 2014.", entity.Message); } [Fact] - public void IncludeExceptionDataInLoggedRow() + public async Task IncludeExceptionDataInLoggedRow() { var exception = new NullReferenceException(); var errorId = Guid.NewGuid(); exception.Data["id"] = errorId; exception.Data["name"] = "ahmed"; - _logger.Log(LogLevel.Error, "execption messege", (Exception)exception); - var entities = GetLogEntities(); + _logger.Log(LogLevel.Error, exception, "execption message"); + var entities = await GetLogEntities(); var entity = entities.Single(); Assert.True(entity.ExceptionData.Contains(errorId.ToString())); Assert.True(entity.ExceptionData.Contains("name=ahmed")); } - [Fact] - public void IncludeExceptionDetailsInLoggedRow() + public async Task IncludeExceptionDetailsInLoggedRow() { var exception = new NullReferenceException(); - _logger.Log(LogLevel.Error, "execption messege", (Exception)exception); - var entity = GetLogEntities().Single(); + _logger.Log(LogLevel.Error, exception, "execption message"); + var entity = (await GetLogEntities()).Single(); Assert.NotNull(entity.Exception); Assert.Equal(exception.ToString().ExceptBlanks(), entity.Exception.ExceptBlanks()); } - [Fact] - public void IncludeInnerExceptionDetailsInLoggedRow() + public async Task IncludeInnerExceptionDetailsInLoggedRow() { var exception = new NullReferenceException("exception message", new DivideByZeroException()); - _logger.Log(LogLevel.Error, "execption messege", (Exception)exception); - var entity = GetLogEntities().Single(); + _logger.Log(LogLevel.Error, exception, "execption message"); + var entity = (await GetLogEntities()).Single(); Assert.NotNull(entity.Exception); Assert.Equal(exception.ToString().ExceptBlanks(), entity.Exception.ExceptBlanks()); Assert.NotNull(entity.InnerException); @@ -107,29 +136,29 @@ public void IncludeInnerExceptionDetailsInLoggedRow() } [Fact] - public void IncludePartitionKeyPrefix() + public async Task IncludePartitionKeyPrefix() { var exception = new NullReferenceException(); - _logger.Log(LogLevel.Error, "execption messege", (Exception)exception); - var entity = GetLogEntities().Single(); + _logger.Log(LogLevel.Error, exception, "execption message"); + var entity = (await GetLogEntities()).Single(); Assert.True(entity.PartitionKey.Contains("customPrefix")); } [Fact] - public void IncludeMachineName() + public async Task IncludeMachineName() { var exception = new NullReferenceException(); - _logger.Log(LogLevel.Error, "execption messege", (Exception)exception); - var entity = GetLogEntities().Single(); + _logger.Log(LogLevel.Error, exception, "execption message"); + var entity = (await GetLogEntities()).Single(); Assert.Equal(entity.MachineName, Environment.MachineName); } [Fact] - public void IncludeGuidAndTimeComponentInRowKey() + public async Task IncludeGuidAndTimeComponentInRowKey() { var exception = new NullReferenceException(); - _logger.Log(LogLevel.Error, "execption messege", (Exception)exception); - var entity = GetLogEntities().Single(); + _logger.Log(LogLevel.Error, (Exception)exception, "execption message"); + var entity = (await GetLogEntities()).Single(); const string splitter = "__"; Assert.True(entity.RowKey.Contains(splitter)); var splitterArray = "__".ToCharArray(); @@ -144,25 +173,39 @@ public void IncludeGuidAndTimeComponentInRowKey() private string GetStorageAccountConnectionString() { - return CloudConfigurationManager.GetSetting("StorageAccountConnectionString"); + //try get connection string from app settings or cloud service config + var connectionStringValue = CloudConfigurationManager.GetSetting("StorageAccountConnectionString"); + if (string.IsNullOrEmpty(connectionStringValue)) + { + //try get connection string from configured AtsOptions + connectionStringValue = AtsOptions.Instance.StorageAccountConnectionString; + } + + return connectionStringValue; } + private CloudStorageAccount GetStorageAccount() { var connectionString = GetStorageAccountConnectionString(); var storageAccount = CloudStorageAccount.Parse(connectionString); return storageAccount; } - private List GetLogEntities() + + private async Task> GetLogEntities() { // Construct the query operation for all customer entities where PartitionKey="Smith". var query = new TableQuery() .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "customPrefix." + GetType())); - var entities = _cloudTable.ExecuteQuery(query); + //var entities = _cloudTable.ExecuteQuery(query); + IList entities = await _cloudTable.ExecuteQueryAsync(query); + return entities.ToList(); } + public void Dispose() { - _cloudTable.DeleteIfExists(); + //_cloudTable.DeleteIfExists(); + _cloudTable.DeleteIfExistsAsync().Wait(); } } } diff --git a/NLog.Extensions.AzureTableStorage.Tests/NLog.Extensions.AzureTableStorage.Tests.csproj b/NLog.Extensions.AzureTableStorage.Tests/NLog.Extensions.AzureTableStorage.Tests.csproj deleted file mode 100644 index 50b5552..0000000 --- a/NLog.Extensions.AzureTableStorage.Tests/NLog.Extensions.AzureTableStorage.Tests.csproj +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - - Debug - AnyCPU - {FFF58919-9BC6-4FFA-B0B4-2197F468813D} - Library - Properties - NLog.Extensions.AzureTableStorage.Tests - NLog.Extensions.AzureTableStorage.Tests - v4.5 - 512 - ..\ - true - 5f660091 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - ..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll - - - False - ..\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll - - - False - ..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll - - - False - ..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.1.0\lib\net40\Microsoft.WindowsAzure.Configuration.dll - - - False - ..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll - - - ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll - - - ..\packages\NLog.3.2.0.0\lib\net45\NLog.dll - - - - - - False - ..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll - - - - - - - - False - ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll - - - False - ..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll - - - False - ..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll - - - - - - - - - - - Always - - - Always - - - Designer - - - Designer - - - - - {69b79032-f3c0-4087-b14e-54e7e91fc4a0} - NLog.Extensions.AzureTableStorage - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - \ No newline at end of file diff --git a/NLog.Extensions.AzureTableStorage.Tests/NLog.Extensions.AzureTableStorage.Tests.xproj b/NLog.Extensions.AzureTableStorage.Tests/NLog.Extensions.AzureTableStorage.Tests.xproj new file mode 100644 index 0000000..e06d667 --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.Tests/NLog.Extensions.AzureTableStorage.Tests.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 2f71836f-3707-4779-829e-ba7f474fff86 + NLog.Extensions.AzureTableStorage.Tests + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + + + + \ No newline at end of file diff --git a/NLog.Extensions.AzureTableStorage.Tests/appsettings.json b/NLog.Extensions.AzureTableStorage.Tests/appsettings.json new file mode 100644 index 0000000..74ddae3 --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.Tests/appsettings.json @@ -0,0 +1,5 @@ +{ + "AppSettings": { + "StorageAccountConnectionString": "UseDevelopmentStorage=true" + } +} diff --git a/NLog.Extensions.AzureTableStorage.Tests/packages.config b/NLog.Extensions.AzureTableStorage.Tests/packages.config deleted file mode 100644 index 680bc8a..0000000 --- a/NLog.Extensions.AzureTableStorage.Tests/packages.config +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/NLog.Extensions.AzureTableStorage.Tests/project.json b/NLog.Extensions.AzureTableStorage.Tests/project.json new file mode 100644 index 0000000..b05d314 --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.Tests/project.json @@ -0,0 +1,23 @@ +{ + "version": "1.0.0-*", + "description": "NLog.Extensions.AzureTableStorage.Tests Class Library", + "tags": [ "" ], + "projectUrl": "", + "licenseUrl": "", + + "dependencies": { + "Microsoft.Extensions.Configuration": "1.0.0-rc1-final-*", + "Microsoft.Extensions.OptionsModel": "1.0.0-rc1-final-*", + "NLog.Extensions.AzureTableStorage": "", + "xunit": "2.1.0", + "xunit.runner.dnx": "2.1.0-rc1-build204" + }, + + "frameworks": { + "dnx451": { } + }, + + "commands": { + "test": "xunit.runner.dnx" + } +} diff --git a/NLog.Extensions.AzureTableStorage.sln b/NLog.Extensions.AzureTableStorage.sln new file mode 100644 index 0000000..03d7938 --- /dev/null +++ b/NLog.Extensions.AzureTableStorage.sln @@ -0,0 +1,47 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{625E4C17-5831-4FF2-914C-C3E326941B87}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3EF3BC13-E023-45DC-959A-6A6C0F97C744}" + ProjectSection(SolutionItems) = preProject + global.json = global.json + NuGet.Config = NuGet.Config + EndProjectSection +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NLog.Extensions.AzureTableStorage", "NLog.Extensions.AzureTableStorage\NLog.Extensions.AzureTableStorage.xproj", "{F27F5ACA-07BD-486D-818C-CC5B26D3446B}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NLog.Extensions.AzureTableStorage.Tests", "NLog.Extensions.AzureTableStorage.Tests\NLog.Extensions.AzureTableStorage.Tests.xproj", "{2F71836F-3707-4779-829E-BA7F474FFF86}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NLog.Extensions.AzureTableStorage.EmptyApplication", "NLog.Extensions.AzureTableStorage.EmptyApplication\NLog.Extensions.AzureTableStorage.EmptyApplication.xproj", "{87D6BDF5-8313-45BE-90CE-D0F8F15C44A9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F27F5ACA-07BD-486D-818C-CC5B26D3446B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F27F5ACA-07BD-486D-818C-CC5B26D3446B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F27F5ACA-07BD-486D-818C-CC5B26D3446B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F27F5ACA-07BD-486D-818C-CC5B26D3446B}.Release|Any CPU.Build.0 = Release|Any CPU + {2F71836F-3707-4779-829E-BA7F474FFF86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2F71836F-3707-4779-829E-BA7F474FFF86}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2F71836F-3707-4779-829E-BA7F474FFF86}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2F71836F-3707-4779-829E-BA7F474FFF86}.Release|Any CPU.Build.0 = Release|Any CPU + {87D6BDF5-8313-45BE-90CE-D0F8F15C44A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {87D6BDF5-8313-45BE-90CE-D0F8F15C44A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {87D6BDF5-8313-45BE-90CE-D0F8F15C44A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {87D6BDF5-8313-45BE-90CE-D0F8F15C44A9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {F27F5ACA-07BD-486D-818C-CC5B26D3446B} = {625E4C17-5831-4FF2-914C-C3E326941B87} + {2F71836F-3707-4779-829E-BA7F474FFF86} = {625E4C17-5831-4FF2-914C-C3E326941B87} + {87D6BDF5-8313-45BE-90CE-D0F8F15C44A9} = {625E4C17-5831-4FF2-914C-C3E326941B87} + EndGlobalSection +EndGlobal diff --git a/NLog.Extensions.AzureTableStorage/AtsCoreServiceCollectionExtensions.cs b/NLog.Extensions.AzureTableStorage/AtsCoreServiceCollectionExtensions.cs new file mode 100644 index 0000000..a33ec86 --- /dev/null +++ b/NLog.Extensions.AzureTableStorage/AtsCoreServiceCollectionExtensions.cs @@ -0,0 +1,15 @@ +using System; +using Microsoft.Extensions.DependencyInjection; + +namespace NLog.Extensions.AzureTableStorage +{ + public static class AtsCoreServiceCollectionExtensions + { + public static void ConfigureAts(this IServiceCollection services, + [NotNull] Action setupAction) + { + var options = AtsOptions.Instance; + setupAction(options); + } + } +} diff --git a/NLog.Extensions.AzureTableStorage/AtsOptions.cs b/NLog.Extensions.AzureTableStorage/AtsOptions.cs new file mode 100644 index 0000000..40540b0 --- /dev/null +++ b/NLog.Extensions.AzureTableStorage/AtsOptions.cs @@ -0,0 +1,25 @@ +using System; + +namespace NLog.Extensions.AzureTableStorage +{ + public class AtsOptions + { + private static AtsOptions _instance; + + public string StorageAccountConnectionString { get; set; } + + private AtsOptions() { } + + public static AtsOptions Instance + { + get + { + if (_instance == null) + { + _instance = new AtsOptions(); + } + return _instance; + } + } + } +} diff --git a/NLog.Extensions.AzureTableStorage/AzureTableStorageTarget.cs b/NLog.Extensions.AzureTableStorage/AzureTableStorageTarget.cs index 5925a0a..8a309f9 100644 --- a/NLog.Extensions.AzureTableStorage/AzureTableStorageTarget.cs +++ b/NLog.Extensions.AzureTableStorage/AzureTableStorageTarget.cs @@ -1,5 +1,5 @@ using System; -using System.ComponentModel.DataAnnotations; +using NLog.Config; using NLog.Targets; namespace NLog.Extensions.AzureTableStorage @@ -10,10 +10,10 @@ public class AzureTableStorageTarget : TargetWithLayout private ConfigManager _configManager; private TableStorageManager _tableStorageManager; - [Required] + [RequiredParameter] public string ConnectionStringKey { get; set; } - [Required] + [RequiredParameter] public string TableName { get; set; } public string PartitionKeyPrefix { get; set; } diff --git a/NLog.Extensions.AzureTableStorage/ConfigManager.cs b/NLog.Extensions.AzureTableStorage/ConfigManager.cs index 8fc2c7b..f6f7e30 100644 --- a/NLog.Extensions.AzureTableStorage/ConfigManager.cs +++ b/NLog.Extensions.AzureTableStorage/ConfigManager.cs @@ -1,6 +1,5 @@ using Microsoft.Azure; using Microsoft.WindowsAzure.Storage; -using System.Configuration; namespace NLog.Extensions.AzureTableStorage { @@ -17,14 +16,12 @@ private string GetStorageAccountConnectionString() { //try get connection string from app settings or cloud service config var connectionStringValue = CloudConfigurationManager.GetSetting(_connectionStringKey); - if (!string.IsNullOrEmpty(connectionStringValue)) return connectionStringValue; - - //try get connection string from ConfigurationManager.ConnectionStrings - var connectionString = ConfigurationManager.ConnectionStrings[_connectionStringKey]; - if (connectionString != null) + if (string.IsNullOrEmpty(connectionStringValue)) { - connectionStringValue = connectionString.ConnectionString; + //try get connection string from configured AtsOptions + connectionStringValue = AtsOptions.Instance.StorageAccountConnectionString; } + return connectionStringValue; } diff --git a/NLog.Extensions.AzureTableStorage/NLog.Extensions.AzureTableStorage.csproj b/NLog.Extensions.AzureTableStorage/NLog.Extensions.AzureTableStorage.csproj deleted file mode 100644 index 8648322..0000000 --- a/NLog.Extensions.AzureTableStorage/NLog.Extensions.AzureTableStorage.csproj +++ /dev/null @@ -1,99 +0,0 @@ - - - - - Debug - AnyCPU - {69B79032-F3C0-4087-B14E-54E7E91FC4A0} - Library - Properties - NLog.Extensions.AzureTableStorage - NLog.Extensions.AzureTableStorage - v4.5 - 512 - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - ..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll - - - False - ..\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll - - - False - ..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll - - - False - ..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.1.0\lib\net40\Microsoft.WindowsAzure.Configuration.dll - - - False - ..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll - - - False - ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll - - - False - ..\packages\NLog.3.2.0.0\lib\net45\NLog.dll - - - - - - - - False - ..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/NLog.Extensions.AzureTableStorage/NLog.Extensions.AzureTableStorage.xproj b/NLog.Extensions.AzureTableStorage/NLog.Extensions.AzureTableStorage.xproj new file mode 100644 index 0000000..7ff5d3a --- /dev/null +++ b/NLog.Extensions.AzureTableStorage/NLog.Extensions.AzureTableStorage.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + f27f5aca-07bd-486d-818c-cc5b26d3446b + NLog.Extensions.AzureTableStorage + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/NLog.Extensions.AzureTableStorage/NotNullAttribute.cs b/NLog.Extensions.AzureTableStorage/NotNullAttribute.cs new file mode 100644 index 0000000..39188fe --- /dev/null +++ b/NLog.Extensions.AzureTableStorage/NotNullAttribute.cs @@ -0,0 +1,9 @@ +using System; + +namespace NLog.Extensions.AzureTableStorage +{ + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] + internal sealed class NotNullAttribute : Attribute + { + } +} diff --git a/NLog.Extensions.AzureTableStorage/Properties/AssemblyInfo.cs b/NLog.Extensions.AzureTableStorage/Properties/AssemblyInfo.cs index 46edf5a..c244197 100644 --- a/NLog.Extensions.AzureTableStorage/Properties/AssemblyInfo.cs +++ b/NLog.Extensions.AzureTableStorage/Properties/AssemblyInfo.cs @@ -1,38 +1,23 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Resources; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("NLog.Extensions.AzureTableStorage")] -[assembly: AssemblyDescription("Azure Table Storage Target for NLog")] +[assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("harouny")] +[assembly: AssemblyCompany("")] [assembly: AssemblyProduct("NLog.Extensions.AzureTableStorage")] -[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyCopyright("Copyright © 2015")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("5f9b332d-1edb-4e18-bc2f-e1d5b5fbd76b")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.4")] -[assembly: AssemblyFileVersion("1.0.0.4")] -[assembly: NeutralResourcesLanguageAttribute("en")] +[assembly: Guid("f27f5aca-07bd-486d-818c-cc5b26d3446b")] diff --git a/NLog.Extensions.AzureTableStorage/TableStorageManager.cs b/NLog.Extensions.AzureTableStorage/TableStorageManager.cs index 56a1ac1..f9223de 100644 --- a/NLog.Extensions.AzureTableStorage/TableStorageManager.cs +++ b/NLog.Extensions.AzureTableStorage/TableStorageManager.cs @@ -13,13 +13,13 @@ public TableStorageManager(ConfigManager configManager, string tableName) var tableClient = storageAccount.CreateCloudTableClient(); //create charts table if not exists. _cloudTable = tableClient.GetTableReference(tableName); - _cloudTable.CreateIfNotExists(); + _cloudTable.CreateIfNotExistsAsync().Wait(); } public void Add(LogEntity entity) { var insertOperation = TableOperation.Insert(entity); - _cloudTable.Execute(insertOperation); + _cloudTable.ExecuteAsync(insertOperation).Wait(); ; } } } diff --git a/NLog.Extensions.AzureTableStorage/app.config b/NLog.Extensions.AzureTableStorage/app.config deleted file mode 100644 index 64f8844..0000000 --- a/NLog.Extensions.AzureTableStorage/app.config +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/NLog.Extensions.AzureTableStorage/packages.config b/NLog.Extensions.AzureTableStorage/packages.config deleted file mode 100644 index 5c54981..0000000 --- a/NLog.Extensions.AzureTableStorage/packages.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/NLog.Extensions.AzureTableStorage/project.json b/NLog.Extensions.AzureTableStorage/project.json new file mode 100644 index 0000000..9b9543d --- /dev/null +++ b/NLog.Extensions.AzureTableStorage/project.json @@ -0,0 +1,25 @@ +{ + "version": "1.0.0-*", + "description": "NLog.Extensions.AzureTableStorage Class Library", + "tags": [ "" ], + "projectUrl": "", + "licenseUrl": "", + + "dependencies": { + "Microsoft.Data.Edm": "5.6.2", + "Microsoft.Data.OData": "5.6.2", + "Microsoft.Data.Services.Client": "5.6.2", + "Microsoft.Extensions.Configuration": "1.0.0-rc1-final-*", + "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final-*", + "Microsoft.WindowsAzure.ConfigurationManager": "3.1.0", + "Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final-*", + "Newtonsoft.Json": "7.0.1", + "NLog": "4.2.1", + "System.Spatial": "5.6.2", + "WindowsAzure.Storage": "6.1.1-preview" + }, + + "frameworks": { + "dnx451": { } + } +} diff --git a/NLog.Extensions.sln b/NLog.Extensions.sln deleted file mode 100644 index 5a1f985..0000000 --- a/NLog.Extensions.sln +++ /dev/null @@ -1,35 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLog.Extensions.AzureTableStorage", "NLog.Extensions.AzureTableStorage\NLog.Extensions.AzureTableStorage.csproj", "{69B79032-F3C0-4087-B14E-54E7E91FC4A0}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLog.Extensions.AzureTableStorage.Tests", "NLog.Extensions.AzureTableStorage.Tests\NLog.Extensions.AzureTableStorage.Tests.csproj", "{FFF58919-9BC6-4FFA-B0B4-2197F468813D}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{576BC019-896A-4287-9399-76FB1DEE0C2C}" - ProjectSection(SolutionItems) = preProject - .nuget\NuGet.Config = .nuget\NuGet.Config - .nuget\NuGet.exe = .nuget\NuGet.exe - .nuget\NuGet.targets = .nuget\NuGet.targets - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {69B79032-F3C0-4087-B14E-54E7E91FC4A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {69B79032-F3C0-4087-B14E-54E7E91FC4A0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {69B79032-F3C0-4087-B14E-54E7E91FC4A0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {69B79032-F3C0-4087-B14E-54E7E91FC4A0}.Release|Any CPU.Build.0 = Release|Any CPU - {FFF58919-9BC6-4FFA-B0B4-2197F468813D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FFF58919-9BC6-4FFA-B0B4-2197F468813D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FFF58919-9BC6-4FFA-B0B4-2197F468813D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FFF58919-9BC6-4FFA-B0B4-2197F468813D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..95143bd --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/README.md b/README.md index dd18a31..095063c 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,26 @@ -NLog Azure Table Storage Target -=============================== +NLog Azure Table Storage Target updated by Greenliff +==================================================== Azure Table Storage Target for NLog For more info about NLog targets and how to use it, refer to How To Write a Target -Download -========== -Download package from Nuget +Original source +=============== +Based on the source available at Github + +Modifications +============= +- Support for ASP.NET 5 RC1 +- Support for NLog 4.2.1 +- Support for WindowsAzure.Storage 6.1.1-preview +- Note that the latest available package Microsoft.WindowsAzure.ConfigurationManager 3.1.0 does not support DNX Core 5.0 +- app.config has been replaced with appsettings.json, see Startup.cs in project NLog.Extensions.AzureTableStorage.EmptyApplication and AzureTableStorageTargetTests.cs in project NLog.Extensions.AzureTableStorage.Tests How to use ========== -- Download package from Nuget. +- There is currently no Nuget package for download available. Add the project NLog.Extensions.AzureTableStorage to your solution. Add the following dependency to your project.json file: "NLog.Extensions.AzureTableStorage": "" +- Configure your application for logging (appsettings.json, NLog.config, create logger). See sample code in Startup.cs of included project NLog.Extensions.AzureTableStorage.EmptyApplication - If you didn't setup Azure storage connection string yet, follow instructions in Setup a storage connection string. - Open NLog configurations file ex: ```NLog.config``` and add the following lines: - Add ```NLog.Extensions.AzureTableStorage``` assemply to ```extensions``` section: diff --git a/global.json b/global.json new file mode 100644 index 0000000..e4870b2 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "projects": [ "src", "test" ], + "sdk": { + "version": "1.0.0-rc1-final" + } +}