Serilog mit Filterausdruck

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Serilog mit Filterausdruck

by Guest » 03 Jan 2025, 13:04

Ich aktualisiere meine alte App, um Serilog zu verwenden. Es handelt sich um die App asp.net C# webForms .NET Framework 4.8.
Die Idee ist:
  • Es gibt insgesamt 3 Senken werden konfiguriert... Datei, Ereignis und Datenbank
  • Standardmäßig sollten alle Protokolle mit einem Mindestmaß an Informationen an die Datenbank und die Ereignisanzeige gesendet werden.
    < li>Ausführliches Protokoll wird in die Datei verschoben.
  • Unten ist die Konfiguration aufgeführt, die ich hinzugefügt habe.
  • Diese Konfiguration schreibt Protokolle in allen drei Senken und filtert nicht nach ausführlichen Protokollen für Dateisenken.
  • Die Protokolldatei enthält alle Protokolle genauso wie die Datenbank und die Ereignisanzeige.
  • Die Filterbedingung funktioniert einwandfrei, wenn sie aus dem Code hinzugefügt wird ... nicht aus der JSON-Konfiguration.
Irgendeine Idee, was fehlt hier.

Code: Select all

{
"Serilog": {
"Using": [ "Serilog.Sinks.File", "Serilog.Sinks.MSSqlServer", "Serilog.Settings.Configuration", "Serilog.Sinks.EventLog", "Serilog.Expressions" ],
"MinimumLevel": {
"Default": "Verbose", // Default logging level
"Override": {
"Microsoft": "Warning", // Override for specific namespaces
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "MSSqlServer",
"Args": {
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}",
"restrictedToMinimumLevel": "Information",
"connectionString": "",
"tableName": "SystemLogEvents",
"autoCreateSqlTable": true
}
},
{
"Name": "File",
"Args": {
"path": "Logs/filtered_logs.log", // Specify the file path
"rollingInterval": "Day", // Log rotation interval
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}"
},
"Filter": [
{
"Name": "ByIncludingOnly",
"Args": {
"expression": "@l = 'Verbose'" // Filter criteria
}
}
]
},
{
"Name": "EventLog",
"Args": {
"restrictedToMinimumLevel": "Information",
"source": "MyApp",
"manageEventSource": true,
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"
}
}
]
}
}

Code: Select all

Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration) // Use the configuration object
//.Filter.ByIncludingOnly(x=>x.Level == LogEventLevel.Verbose)
.CreateLogger();


Top