Using NLog For Diagnostic Logging In Windows Azure Cloud Services And Writing The Logs To Azure Table Storage

November 6 2015

I’ve never liked the default logging mechanisms in Azure for application event logging.  Parsing the WADDiagnosticInfrastructureLogsTable is always such a hassle. Events I’ve written are mixed in with all the other events that Azure is firing all the time, and everything in my event is jammed into a single field.

So, for my current Azure project, I switched to using NLog and love it!  I used the NLog extension for writing events to Azure table storage: – you’ll notice that isn’t the master Git repository, but the master one doesn’t have the right updated!  But I’m using and it works great.

I am setting the connection string via code so that I pick up the string based on the local config or cloud config, aka

var azureStorageTarget = (AzureTableStorageTarget)
azureStorageTarget.ConnectionString = RoleEnvironment.GetConfigurationSettingValue


And wow so much better. Some of the overloads are so nifty, like the ability to just give the exception to the logger, or letting the logger do the string formatting.  Nice!

Below is a sample project showing both a web role and a worker role using NLog and logging to table storage. (495.15 kb)

Add comment

  • Comment
  • Preview