Tengo varios sumideros de Serilog en mi aplicación ASP.NET WEB API .NET Core 3. Uno de los sumideros es MS SQL donde me gustaría escribir SOLO mensajes de error. Aquí hay una parte de mi appsettings.json
"Serilog": { "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Debug", "Serilog.Sinks.File", "Serilog.Sinks.MSSqlServer" ], "MinimumLevel": { "Default": "Debug", "Override": { "Microsoft": "Information", "System": "Information" } }, "WriteTo": [ { "Name": "Console" }, { "Name": "Debug" }, { "Name": "File", "Args": { "path": "Logs/log_.txt", "rollingInterval": "Minute", "shared": true } }, { "Name": "MSSqlServer", "Args": { "connectionString": "CONNECTIONSTRING", "sinkOptionsSection": { "tableName": "Logs", "schemaName": "EventLogging", "autoCreateSqlTable": true, "batchPostingLimit": 50, "restrictedToMinimumLevel": "Error", "period": "0.00:00:30" } } } ], "Enrich": [ "FromLogContext", "WithMachineName" ] }Pero finalmente recibí algunos mensajes de información y nivel de depuración en la tabla de registro de SQL.
¿Qué hay de malo con la configuración anterior? ¿Por qué no ayudó limitedToMinimumLevel ?
Si quiero excluir un mensaje inferior a la información, debo configurarlo en la subsección Predeterminado de la sección Nivel mínimo .
Pero en este caso no puedo especificar un mensaje de nivel inferior para un sumidero en particular. Por ejemplo
"restrictedToMinimumLevel":"Debug"no ayudará: los mensajes de depuración no se escribirán en MS SQL.
El restrictedToMinimumLevel es el elemento secundario de Args . Revisa los documentos .
Tratar:
"WriteTo": [ { "Name": "Console" }, { "Name": "Debug" }, { "Name": "File", "Args": { "path": "Logs/log_.txt", "rollingInterval": "Minute", "shared": true } }, { "Name": "MSSqlServer", "Args": { "connectionString": "CONNECTIONSTRING", "sinkOptionsSection": { "tableName": "Logs", "schemaName": "EventLogging", "autoCreateSqlTable": true, "batchPostingLimit": 50, "period": "0.00:00:30" }, "restrictedToMinimumLevel": "Error", } } ],