为什么未实现 Serilog LoggerEnrichmentConfiguration 操作



我得到:

ArgumentException: Configuration for Action<Serilog.Configuration.LoggerEnrichmentConfiguration> is not implemented.

我有一个这样的配置,松散地基于示例:

{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"LevelSwitches": { "$controlSwitch": "Verbose" },
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"MyApp.Something.Tricky": "Verbose"
}
},
"WriteTo:Async": {
"Name": "Async",
"Args": {
"configure": [
{
"Name": "File",
"Args": {
"outputTemplate": "{Timestamp:o} [{Level:u3}] ({Application}/{MachineName}/{ThreadId}/{ThreadName}) {Message}{NewLine}{Exception}"
}
}
]
}
},
"Enrich": [
"FromLogContext",
"WithThreadId",
{
"Name": "AtLevel",
"Args": {
"enrichFromLevel": "Error",
"configureEnricher": [ "WithThreadName" ]
}
},
{
"Name": "When",
"Args": {
"expression": "Application = 'MySample.Service'",
"configureEnricher": [ "WithMachineName" ]
}
}
],
"Properties": {
"Application": "MySample.Service"
},
"Destructure": [
{
"Name": "With",
"Args": { "policy": "MySample.Logging.CustomPolicy, MySample.Service" }
},
{
"Name": "ToMaximumDepth",
"Args": { "maximumDestructuringDepth": 3 }
},
{
"Name": "ToMaximumStringLength",
"Args": { "maximumStringLength": 10 }
},
{
"Name": "ToMaximumCollectionCount",
"Args": { "maximumCollectionCount": 5 }
}
],
"Filter": [
{
"Name": "ByIncludingOnly",
"Args": {
"expression": "Application = 'MySample.Service'"
}
},
{
"Name": "With",
"Args": {
"filter": "MySample.Logging.CustomFilter, MySample.Service"
}
}
]
}
}

还有这样的Logging支持类:

静态类日志记录 { internal static ILogger Logger { get; } = BuildConfiguration((。CreateLogger((; 私有静态 DateTime Now { get; } = DateTime.Now; 私有静态字符串 GetLogFilePath(字符串子系统 = null( { var fileNameWithoutExtenskion = Assembly.GetExecutingAssembly((.Location.GetFileNameWithoutExtension((; var nowTimeStamp = Now.ToString("s"(.替换(":", "_"(; 常量字符串点日志 = ".log"; var log文件名 = IsNullOrEmpty(子系统( ?Join("-", $"{fileNameWithoutExtenskion}", $"{nowTimeStamp}{dotlog}"( : Join("-", $"{fileNameWithoutExtenskion}", subsystem, $"{nowTimeStamp}{dotlog}"(; const string myComp = "My Comp"; 返回 CommonApplicationData.GetFolderPath((。Combine(myComp, logFileName(; } 私有静态 ILogger CreateLogger(this IConfigurationRoot root( { 常量字符串错误 = 名称(错误(; 返回新的记录器配置(( .ReadFrom.Configuration(root( .Enrich.FromLogContext(( .WriteTo.Async(a => a.File(GetLogFilePath(((/*, monitor: new MonitorConfiguration((*/( .WriteTo.Conditional( e => new[] { LogEventLevel.Error, LogEventLevel.Fatal }.包含(e.级别( , a => a.File(GetLogFilePath(errors(( ) .CreateLogger((; } 私有静态 IConfiguration根构建配置(( { var execAssyLocation = Assembly.GetExecutingAssembly((.位置; var jsonFilePath = Path.Combine(execAssyLocation.GetDirectoryName((, "appsettings.json"(; 返回新的配置生成器(( .AddJsonFile(path: jsonFilePath, optional: false, reloadOnChange: true( .构建((; } 私有静态字符串 Combine(this string path, params string[] paths( => Path.Combine( 路径。任何(( ?新字符串[] { 路径 }。连接(路径(。ToArray(( : new string[] { path } ); 私有静态字符串 GetFileNameWithoutExtension(此字符串路径( => Path.GetFileNameWithoutExtension(path(; 私有静态字符串 GetDirectoryName(此字符串路径( => Path.GetDirectoryName(path(; 私有静态字符串 GetFolderPath(this Environment.SpecialFolder folder( => Environment.GetFolderPath(folder(; }

据我所知,我已经引用了所有必要的软件包。

事实证明,这是我需要引用Serilog.Settings.Configuration包的开发版本的问题。然后它突然开始工作。

最新更新