mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-18 09:17:52 +02:00
Logging for DBContexts
This commit is contained in:
@ -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<NotificationsContext> options
|
||||
{
|
||||
public DbSet<NotificationConnector> NotificationConnectors { get; set; }
|
||||
public DbSet<Notification> 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user