Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 滚动文件名中的Serilog自定义上下文,Nlog上下文_C#_Nlog_Serilog - Fatal编程技术网

C# 滚动文件名中的Serilog自定义上下文,Nlog上下文

C# 滚动文件名中的Serilog自定义上下文,Nlog上下文,c#,nlog,serilog,C#,Nlog,Serilog,类似于,但不是在日志文件(outputTemplate)中,我想命名该文件 此外,我试图在使用WriteTo.LiterateConsole+WriteTo.RollingFile和WriteTo.NLog之间切换,以维护自定义上下文 但是,为了完成自定义滚动文件命名,我基本上需要在记录器初始化时提供名称,如下所示: var c = new LoggerConfiguration() .Enrich.WithProperty(/* some standard stuff */)

类似于,但不是在日志文件(
outputTemplate
)中,我想命名该文件

此外,我试图在使用
WriteTo.LiterateConsole+WriteTo.RollingFile
WriteTo.NLog
之间切换,以维护自定义上下文

但是,为了完成自定义滚动文件命名,我基本上需要在记录器初始化时提供名称,如下所示:

var c = new LoggerConfiguration()
    .Enrich.WithProperty(/* some standard stuff */)
    .WriteTo.LiterateConsole(minLevel)
    .WriteTo.RollingFile(string.IsNullOrEmpty(customName) ? "logs\log-{Date}.txt" : "logs\"+customName+".log.{Date}.txt") // <-- would have thought I could use `{SourceContext}` as placeholder...
    .CreateLogger()
    .ForContext(Constants.SourceContextPropertyName, customName) // <-- not sure if I need this here
    ;
这样初始化:

var c = new LoggerConfiguration()
    .Enrich.WithProperty(/* some standard stuff */)
    .Enrich.WithProperty(Constants.SourceContextPropertyName, customName) // <-- is this the trick?
    .WriteTo.Nlog(minLevel)
    .CreateLogger()
    .ForContext(Constants.SourceContextPropertyName, customName) // <-- not sure if this is redundant with enrichment above
    ;
var c=new LoggerConfiguration()
.Enrich.WithProperty(/*一些标准材料*/)

.Enrich.WithProperty(Constants.SourceContextPropertyName,customName)//这是一个只包含链接的答案,所以我只做评论,但我在找到你的问题后发现了这一点:-看起来很有希望。该链接的作者@sander schutten实际上回答了我的问题,但主持人删除了它?
var c = new LoggerConfiguration()
    .Enrich.WithProperty(/* some standard stuff */)
    .Enrich.WithProperty(Constants.SourceContextPropertyName, customName) // <-- is this the trick?
    .WriteTo.Nlog(minLevel)
    .CreateLogger()
    .ForContext(Constants.SourceContextPropertyName, customName) // <-- not sure if this is redundant with enrichment above
    ;