feat: enhance logging configuration with async file logging for SQL commands

This commit is contained in:
2026-07-07 17:26:23 -04:00
parent 421a8cc092
commit 4f651fc239
2 changed files with 29 additions and 7 deletions
@@ -169,14 +169,10 @@ public static class ServiceCollectionExtensions
var lockingBehavior = serviceProvider.GetRequiredService<IEntityFrameworkCoreLockingBehavior>(); var lockingBehavior = serviceProvider.GetRequiredService<IEntityFrameworkCoreLockingBehavior>();
lockingBehavior.Initialise(opt); lockingBehavior.Initialise(opt);
// Enable SQL query logging when log level is Debug
var loggerFactory = serviceProvider.GetService<Microsoft.Extensions.Logging.ILoggerFactory>(); var loggerFactory = serviceProvider.GetService<Microsoft.Extensions.Logging.ILoggerFactory>();
if (loggerFactory != null)
{
opt.UseLoggerFactory(loggerFactory) opt.UseLoggerFactory(loggerFactory)
.EnableSensitiveDataLogging() .EnableSensitiveDataLogging()
.EnableDetailedErrors(); .EnableDetailedErrors();
}
}); });
return serviceCollection; return serviceCollection;
@@ -32,6 +32,32 @@
} }
] ]
} }
},
{
"Name": "Async",
"Args": {
"configure": [
{
"Name": "File",
"Args": {
"path": "%JELLYFIN_LOG_DIR%//sql_.log",
"rollingInterval": "Day",
"retainedFileCountLimit": 3,
"rollOnFileSizeLimit": true,
"fileSizeLimitBytes": 100000000,
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message}{NewLine}{Exception}"
}
}
]
},
"Filter": [
{
"Name": "ByIncludingOnly",
"Args": {
"expression": "SourceContext = 'Microsoft.EntityFrameworkCore.Database.Command'"
}
}
]
} }
], ],
"Enrich": [ "FromLogContext", "WithThreadId" ] "Enrich": [ "FromLogContext", "WithThreadId" ]