Skip to content

Latest commit

 

History

History
55 lines (47 loc) · 2.59 KB

File metadata and controls

55 lines (47 loc) · 2.59 KB

NLog Azure Table Storage Target

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

How to use

  • Download package from Nuget.
  • 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:
  <extensions>
    <add assembly="NLog.Extensions.AzureTableStorage"/>
  </extensions>
  • Add AzureTableStorage target to targets section:
  <targets>
    <target xsi:type="AzureTableStorage" 
            name="[[target-name]]"
            ConnectionStringKey="[[connection-string-key]]" 
            TableName="[[table-name]]"
			PartitionKeyPrefix="[[partition-key-prefix-value]]"
			PartitionKeyPrefixKey="[[partition-key-prefix-configuration-key]]" />
  </targets>

Where [[target-name]] is a name you give for the target, [[connection-string-key]] is the key of Azure Storage Account connection string setting in App Settings or Cloud Service configuration file, and [[table-name]] is a name you give to the log table that will be created.

If multiple applications need to share the same storage account it is possible to prefix the partition keys used with a custom string. [[PartitionKeyPrefix]] and [[PartitionKeyPrefixKey]] are optional and [[PartitionKeyPrefixKey]] has precedence over a hard coded value in [[PartitionKeyPrefix]].

  • Add a rule that uses the target in rules section.
  <rules>
    <logger name="*" minlevel="Trace" writeTo="[[target-name]]" />
  </rules> 

Note: You can also configure this by code refer to How To Write a Target for more information.

How to View Logs?

A lot of ways you can access table storage.

Notes

  • Before running tests on you local machine, make sure Azure Storage Emulator is running.