diff --git a/API/Schema/Contexts/LibraryContext.cs b/API/Schema/Contexts/LibraryContext.cs index 8d13ef6..bbe9e3c 100644 --- a/API/Schema/Contexts/LibraryContext.cs +++ b/API/Schema/Contexts/LibraryContext.cs @@ -1,12 +1,26 @@ using API.Schema.LibraryConnectors; +using log4net; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace API.Schema.Contexts; public class LibraryContext(DbContextOptions options) : DbContext(options) { public DbSet LibraryConnectors { get; set; } + + private ILog Log => LogManager.GetLogger(GetType()); + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + base.OnConfiguring(optionsBuilder); + optionsBuilder.EnableSensitiveDataLogging(); + optionsBuilder.LogTo(s => + { + Log.Debug(s); + }, [DbLoggerCategory.Query.Name], LogLevel.Trace, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category); + } + protected override void OnModelCreating(ModelBuilder modelBuilder) { //LibraryConnector Types diff --git a/API/Schema/Contexts/NotificationsContext.cs b/API/Schema/Contexts/NotificationsContext.cs index 26f5699..8fe9454 100644 --- a/API/Schema/Contexts/NotificationsContext.cs +++ b/API/Schema/Contexts/NotificationsContext.cs @@ -1,5 +1,7 @@ using API.Schema.NotificationConnectors; +using log4net; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace API.Schema.Contexts; @@ -7,4 +9,15 @@ public class NotificationsContext(DbContextOptions options { public DbSet NotificationConnectors { get; set; } public DbSet Notifications { get; set; } + + private ILog Log => LogManager.GetLogger(GetType()); + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + base.OnConfiguring(optionsBuilder); + optionsBuilder.EnableSensitiveDataLogging(); + optionsBuilder.LogTo(s => + { + Log.Debug(s); + }, [DbLoggerCategory.Query.Name], LogLevel.Trace, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category); + } } \ No newline at end of file diff --git a/API/Schema/Contexts/PgsqlContext.cs b/API/Schema/Contexts/PgsqlContext.cs index 7308472..aa1b25b 100644 --- a/API/Schema/Contexts/PgsqlContext.cs +++ b/API/Schema/Contexts/PgsqlContext.cs @@ -1,6 +1,8 @@ using API.Schema.Jobs; using API.Schema.MangaConnectors; +using log4net; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace API.Schema.Contexts; @@ -13,7 +15,18 @@ public class PgsqlContext(DbContextOptions options) : DbContext(op public DbSet Chapters { get; set; } public DbSet Authors { get; set; } public DbSet Tags { get; set; } + private ILog Log => LogManager.GetLogger(GetType()); + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + base.OnConfiguring(optionsBuilder); + optionsBuilder.EnableSensitiveDataLogging(); + optionsBuilder.LogTo(s => + { + Log.Debug(s); + }, [DbLoggerCategory.Query.Name], LogLevel.Trace, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category); + } + protected override void OnModelCreating(ModelBuilder modelBuilder) { //Job Types