I have ASP .Net Core WebApi application that is using .Net Framework 4.6. I am using NLog for logging. I want to log to Azure Table Storage. For that I am using AzureTableStorageNLogTarget and NLogExtensions.Logging Nuget Packages.
Latest Stable Release for AzureTableStorageNLogTarget is 1.0.9 but when I use that I am getting following Exception:
Could not load type 'Microsoft.Azure.CloudConfigurationManager' from assembly
So I am using version 1.0.8.
Now I am getting following exception:
Error Error initializing target 'AzureTableStorage Target[AzureTableStorageTarget]'. Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: connectionString
Googling the error gives me that It is not able to find Azure Table Storage ConnectionString, I don't understand why.
Here is my NLog.Config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Warn"
internalLogFile="c:\temp\internal-nlog.txt">
<extensions>
<add assembly="NLog.Extensions.AzureTableStorage"/>
</extensions>
<!-- define various log targets -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="allfile" fileName="c:\temp\WebAPI-nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|${message} ${exception}" />
<target xsi:type="File" name="ownFile-web" fileName="c:\temp\WebAPI-nlog-own-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}| ${message} ${exception}" />
<target xsi:type="AzureTableStorage"
name="AzureTableStorageTarget"
ConnectionStringKey="AzureStorageConnectionString"
TableName="LogTable" />
<target xsi:type="Null" name="blackhole" />
</targets>
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
<!--Skip Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
<logger name="*" minlevel="Trace" writeTo="AzureTableStorageTarget" />
</rules>
</nlog>
And my Appsetting.json:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"AppSettings": {
"AzureStorageConnectionString": "DefaultEndpointsProtocol=https;AccountName=sqdev01storage;AccountKey=<key redacted>"
}
}
A sample project is available on Git at: https://github.com/pankyog/NLogToAzureTable/tree/Re1