Use Serilog in EntityFramework Core logging.

This commit is contained in:
2025-07-24 21:23:53 +01:00
parent 1435aa10ee
commit bf19439e49
15 changed files with 69 additions and 36 deletions

View File

@@ -41,13 +41,13 @@ public sealed class Context(DbContextOptions options) : DbContext(options)
public DbSet<MediaByMachine> MediasByMachines { get; set; }
public DbSet<RomSetStat> RomSetStats { get; set; }
public static Context Create(string dbPath)
public static Context Create(string dbPath, ILoggerFactory loggerFactory)
{
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseLazyLoadingProxies()
#if DEBUG
.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()))
.UseLoggerFactory(loggerFactory)
#endif
.UseSqlite($"Data Source={dbPath}");

View File

@@ -24,10 +24,12 @@
*******************************************************************************/
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Logging;
namespace RomRepoMgr.Database;
public class ContextFactory : IDesignTimeDbContextFactory<Context>
{
public Context CreateDbContext(string[] args) => Context.Create("romrepo.db");
public Context CreateDbContext(string[] args) =>
Context.Create("romrepo.db", LoggerFactory.Create(builder => builder.AddConsole()));
}