简体   繁体   English

Serilog RavenDb接收器无法在asp.net 5应用程序中工作

[英]Serilog RavenDb sink not working in an asp.net 5 app

I am looking at serilog and running a few tests. 我正在看serilog并进行一些测试。 So far it is working fine writing to the console or file. 到目前为止,它可以很好地写入控制台或文件。 However I am not having any luck getting it to work with the RavenDb sink. 但是我没有运气能与RavenDb接收器一起使用。 I am trying to get this working in an asp.net 5 app. 我正在尝试使它在asp.net 5应用程序中工作。 I have reviewed the following articles: 我已经阅读了以下文章:

http://nblumhardt.com/2015/05/diagnostic-logging-in-dnx-asp-net-5/ http://nblumhardt.com/2013/06/serilog-and-ravendb/ http://nblumhardt.com/2015/05/diagnostic-logging-in-dnx-asp-net-5/ http://nblumhardt.com/2013/06/serilog-and-ravendb/

I started with an empty app, and added the following dependencies in project.json. 我从一个空的应用程序开始,并在project.json中添加了以下依赖项。

"Serilog.Framework.Logging": "1.0.0-rc1-final-10071",
"Serilog.Sinks.RavenDB": "1.5.4",
"RavenDB.Client": "3.0.30000"

I also removed dnxcore. 我还删除了dnxcore。

Then I added the following code in startup.cs: 然后,我在startup.cs中添加了以下代码:

public Startup()
{
    var documentStore = new DocumentStore()
    {
        Url = "http://localhost:8080",
        DefaultDatabase = "Logs"
    }.Initialize();

    Log.Logger = new LoggerConfiguration()
       .WriteTo.File(@"c:\temp\log.txt")
       .WriteTo.Console()
       .WriteTo.RavenDB(documentStore)
       .CreateLogger();
}

public void ConfigureServices(IServiceCollection services)
{
}

public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
    loggerFactory.AddSerilog();
    app.UseIISPlatformHandler();

    app.Run(async (context) =>
    {
        Log.Information("Hello World");
        await context.Response.WriteAsync("Hello World!");
    });
}

Everything gets logged to the file and console just fine, and the Logs database gets created, but no log entries are stored in RavenDb. 一切都很好地记录到了文件和控制台中,并且创建了Logs数据库,但是在RavenDb中没有存储任何日志条目。

I have tried various log levels. 我尝试了各种日志级别。 I tried reducing the batch size. 我试图减小批量大小。 I suspected this had something to do with the lifecycle of the document store, so I added the following in the ConfigureServices method. 我怀疑这与文档存储的生命周期有关,因此我在ConfigureServices方法中添加了以下内容。

services.AddSingleton(x =>
{
   return new DocumentStore()
   {
       Url = "http://localhost:8080/",
       DefaultDatabase = "Test",
   }.Initialize();
}

Then I moved the logger configuration code into the Configure method and used DI instance, but that doesn't work either. 然后,我将记录器配置代码移到Configure方法中,并使用了DI实例,但这也不起作用。 I can store other objects in RavenDb using the same DocumentStore just fine. 我可以使用相同的DocumentStore将其他对象存储在RavenDb中。

Have I missed a configuration setting or something? 我错过了配置设置吗?

I was able to get this working with the latest RavenDb client. 我能够使用最新的RavenDb客户端进行此操作。 I created a new (package) style library, added Serilog nuget package v2.0.0-beta-403, added the RavenDB.Client v3 nuget package, and dropped in the .cs files from the existing Serilog.Sinks.RavenDb library. 我创建了一个新的(程序包)样式库,添加了Serilog nuget程序包v2.0.0-beta-403,添加了RavenDB.Client v3 nuget程序包,并将其从现有Seri​​log.Sinks.RavenDb库放入.cs文件中。 It compiled and worked, I didn't have to change any code. 它编译并工作了,我不必更改任何代码。

I haven't had a chance to test it much yet, but it seem to be working fine. 我还没有机会进行大量测试,但是它似乎运行良好。 Of course I don't know how stable Serilog v2 beta is, or how long until it is released. 当然,我不知道Serilog v2 beta的稳定性如何,或者直到发行多久。 The nice thing is that serilog v2 supports .netcore. 令人高兴的是serilog v2支持.netcore。 Unfortunately the RavenDb client doesn't, at least not yet. 不幸的是,RavenDb客户端还没有,至少现在还没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM