我正在查看 serilog 并运行一些测试。到目前为止,它可以正常写入控制台或文件。但是,我没有任何运气让它与 RavenDb 接收器一起工作。我试图让它在 asp.net 5 应用程序中工作。我审查了以下文章:
http://nblumhardt.com/2015/05/diagnostic-logging-in-dnx-asp-net-5/ http://nblumhardt.com/2013/06/serilog-and-ravendb/
我从一个空的应用程序开始,并在 project.json 中添加了以下依赖项。
"Serilog.Framework.Logging": "1.0.0-rc1-final-10071",
"Serilog.Sinks.RavenDB": "1.5.4",
"RavenDB.Client": "3.0.30000"
我还删除了 dnxcore。
然后我在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!");
});
}
一切都很好地记录到文件和控制台,并创建了日志数据库,但没有日志条目存储在 RavenDb 中。
我尝试了各种日志级别。我尝试减少批量大小。我怀疑这与文档存储的生命周期有关,所以我在ConfigureServices
方法中添加了以下内容。
services.AddSingleton(x =>
{
return new DocumentStore()
{
Url = "http://localhost:8080/",
DefaultDatabase = "Test",
}.Initialize();
}
然后我将记录器配置代码移动到Configure
方法中并使用了 DI 实例,但这也不起作用。我可以使用相同的方式将其他对象存储在 RavenDb 中DocumentStore
。
我错过了配置设置吗?