2017-07-12 28 views
0

在Nlog.config文件中使用NLog.Extensions.AzureTableStorage的擴展名時,試圖將日誌插入到Azure表存儲中,但在Azure表存儲的目標類型下出現錯誤。帶AzureTableStorage的NLog

錯誤: - 這是無效的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

沒有足夠的細節。 – user9993

+0

<! - 設置了一個藍色的存儲表的目標 - > <目標名稱= 「AzureTableStorage」 的xsi:type = 「AzureTableStorage」 PartitionKey = 「$ {日期} $ {記錄器}」 RowKey =「$ {ticks}。$ {guid}「 ConnectionString =」UseDevelopmentStorage = true「 tableName =」TempAzureTableStorageTargetTestsLogs「/> user1555245

+0

https://stackoverflow.com/help/how-to-ask – user9993

回答

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 &我加入Nlog.extensions.azuretablestorage擴展(的NuGet版本1.1.4)

據我所知,對於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 Table中存儲目標的詳細信息,你可以參考NLog.Extensions.AzureTableStorage。另外,您可以參考NLog瞭解更多教程。