【问题标题】:Write to Azure documentDb with SeriLog使用 SeriLog 写入 Azure documentDb
【发布时间】:2016-04-08 19:35:33
【问题描述】:

我已经使用 DocumentDB 在 Azure 中设置了一个包含集合的数据库。我可以使用数据库连接、查询、更新整个 CRUD。现在我正在添加 seriLog,这样我就可以将错误记录到我的新数据库中。 SeriLog 有一个用于 Azure DocumentDb 的接收器。你可以通过 NuGet 安装它:

       Install-Package Serilog.Sinks.AzureDocumentDb

这样做后,我执行以下测试以通过 seriLog 向我的数据库写入一些内容:

                Uri uri = new Uri(ConfigurationManager.AppSettings["endpoint"]);
        DateTimeOffset timestamp = new DateTimeOffset(DateTime.Now);
        Exception exception = new Exception("This is just a test");
        IEnumerable<MessageTemplateToken> tokens = new List<MessageTemplateToken>();
        MessageTemplate messageTemplate = new MessageTemplate(tokens);
        IEnumerable<LogEventProperty> properties = new List<LogEventProperty>();
        LogEvent logEvent = new LogEvent(timestamp, LogEventLevel.Information,exception,messageTemplate,properties);
        var azure = new AzureDocumentDBSink(uri, ConfigurationManager.AppSettings["authKey"], ConfigurationManager.AppSettings["database"], "Items",null);
        azure.Emit(logEvent);

当我尝试编译这个项目时,我得到以下信息:

    Error   CS1705  Assembly 'Serilog.Sinks.AzureDocumentDB' with identity  
    'Serilog.Sinks.AzureDocumentDB, Version=1.5.0.0, 
    Culture=neutral, PublicKeyToken=24c2f752a8e58a10' uses 'Serilog,  
     Version=1.5.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10' 
     which has a higher version than referenced assembly 
    'Serilog' with identity 'Serilog, Version=1.4.0.0, Culture=neutral,  
    PublicKeyToken=24c2f752a8e58a10'    

我查看了 app.config 并看到以下内容:

       <dependentAssembly>
    <assemblyIdentity name="Serilog" publicKeyToken="24c2f752a8e58a10" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.4.0.0" newVersion="1.4.0.0" />
  </dependentAssembly>

通常情况下,当这种情况发生时,我只会更新参考,然后就可以了。但事实并非如此。我从 VS2015 中的一个空白控制台应用程序开始,安装了 NuGet 包,添加了代码并尝试运行它。有谁知道为什么会发生这种情况以及如何解决?谢谢

【问题讨论】:

    标签: c# azure azure-cosmosdb serilog


    【解决方案1】:

    这是包的 NuSpec 的问题;它已在 Serilog.Sinks.DocumentDB 版本 1.5.8 中得到修复,该版本现已发布。

    Update-Package Serilog
    Update-Package Serilog.Sinks.AzureDocumentDB
    

    包管理器控制台(VS)会整理出来。

    【讨论】:

    • 谢谢 Nicholas..我在推特上告诉了你这个问题,你也在那里回复了。它的工作原理!
    【解决方案2】:

    您是否尝试过删除 Serilog 以及 Serilog.Sinks.AzureDocumentDb 包,然后重新添加 Serilog.Sinks.AzureDocumentDb?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-23
      • 2017-10-05
      • 2022-10-24
      • 1970-01-01
      • 1970-01-01
      • 2021-03-10
      • 2019-02-24
      • 1970-01-01
      相关资源
      最近更新 更多