NLog与AzureTableStorage

时间:2017-07-12 10:17:03

标签: azure nlog azure-table-storage

尝试将日志插入Azure表存储,同时在Nlog.config文件中使用NLog.Extensions.AzureTableStorage的扩展名,我在azure表存储的目标类型下收到错误。

错误: - 这是无效的xsi:type http://www.nlog-project.org/schemas/NLog.xsd:AzureTableStorage

仅供参考 - 我使用的是最新版本的Nlog最新版本4.4.11&我添加了Nlog.extensions.azuretablestorage(Nuget版本1.1.4)的扩展

更新配置文件:

<extensions> 
  <add assembly="NLog.Extensions.AzureTableStorage"/> 
</extensions> 
<!-- set up a an azure storage table target --> 
<targets>
  <target name="AzureTableStorage" xsi:type="AzureTableStorage" PartitionKey="${date}.${logger}" RowKey="${ticks}.${guid}" ConnectionString="UseDevelopmentStorage=true" tableName="TempAzureTableStorageTargetTestsLogs" /> 
</targets>

1 个答案:

答案 0 :(得分:0)

  

这是无效的xsi:type http://www.nlog-project.org/schemas/NLog.xsd:AzureTableStorage

我假设您安装了NLog.Config,会自动创建默认NLog.config。由于此软件包引用NLog.Schema,因此在编辑NLog配置文件时将启用Intellisense(TM)。

我已经检查了这个问题,上面的消息仅用于警告,日志记录功能没问题。你可以删除NLog.Config和NLog.Config包,然后警告消息就会消失。

  

仅供参考 - 我使用的是最新版本的Nlog最新版本4.4.11&amp;我添加了Nlog.extensions.azuretablestorage(Nuget版本1.1.4)的扩展

AFAIK,NLog Azure Table Storage Target的最新版本是1.0.11。这是我的代码片段,您可以参考它:

<强> 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"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">

  <extensions>
    <add assembly="NLog.Extensions.AzureTableStorage"/>
  </extensions>

  <targets>
    <target xsi:type="AzureTableStorage" 
            name="NLogAzureTable"
            ConnectionStringKey="NLog.Azure.TableStorage.ConnectionString" 
            TableName="NLogTable"/>
  </targets>

  <rules>
    <logger name="*" minlevel="Info" writeTo="NLogAzureTable" />
    <logger name="*" minlevel="Info" writeTo="console" />
  </rules>
</nlog>

<强>的App.config

<appSettings>
  <add key="NLog.Azure.TableStorage.ConnectionString" value="{your-storage-account-connectionString}" />
</appSettings>

<强>用法:

var logger = LogManager.GetLogger(nameof(Program));
logger.Info("hello world!!!");

<强>结果:

enter image description here

有关如何配置NLog Azure表存储目标的更多详细信息,请参阅NLog.Extensions.AzureTableStorage。另外,您可以参考NLog获取更多教程。