Suppress logging of EF commands

This commit is contained in:
Pat Hartl 2024-09-18 21:06:25 -05:00
parent 48479a55d2
commit b6d76a2f0c
3 changed files with 8 additions and 1 deletions

View file

@ -9,6 +9,7 @@ using Serilog;
var settings = SettingService.GetSettings();
using var logger = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", Serilog.Events.LogEventLevel.Warning)
.Enrich.WithProperty("Application", typeof(Program).Assembly.GetName().Name)
.WriteTo.Console()
.WriteTo.File(Path.Combine(settings.Debug.LoggingPath, "log-.txt"), rollingInterval: settings.Debug.LoggingArchivePeriod)

View file

@ -1,21 +1,26 @@
using LANCommander.Launcher.Data.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace LANCommander.Launcher.Data
{
public class DatabaseContext : DbContext
{
private readonly ILoggerFactory LoggerFactory;
public DatabaseContext() { }
public DatabaseContext(DbContextOptions options)
public DatabaseContext(ILoggerFactory loggerFactory, DbContextOptions options)
: base(options)
{
LoggerFactory = loggerFactory;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var dbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LANCommander.db");
optionsBuilder.UseLoggerFactory(LoggerFactory);
optionsBuilder.UseSqlite($"Data Source={dbPath};Cache=Shared");
optionsBuilder.UseLazyLoadingProxies();
}

View file

@ -31,6 +31,7 @@ namespace LANCommander.Launcher
var settings = SettingService.GetSettings();
using var Logger = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", Serilog.Events.LogEventLevel.Warning)
.Enrich.WithProperty("Application", typeof(Program).Assembly.GetName().Name)
.WriteTo.File(Path.Combine(settings.Debug.LoggingPath, "log-.txt"), rollingInterval: settings.Debug.LoggingArchivePeriod)
#if DEBUG