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 package from Nuget
- 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 toextensions
section:
<extensions>
<add assembly="NLog.Extensions.AzureTableStorage"/>
</extensions>
- Add
AzureTableStorage
target totargets
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.
A lot of ways you can access table storage.
- Before running tests on you local machine, make sure Azure Storage Emulator is running.