Skip to content

Commit 5ac68b3

Browse files
committed
db debug logger
1 parent a49db87 commit 5ac68b3

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

Intersect.Server/Database/IntersectDbContext.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,17 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
5555
(ContextOptions.ReadOnly && !ContextOptions.ExplicitLoad
5656
? QueryTrackingBehavior.NoTracking
5757
: QueryTrackingBehavior.TrackAll);
58+
59+
var loggerFactory = ContextOptions.LoggerFactory;
60+
#if DEBUG
61+
loggerFactory ??= new IntersectLoggerFactory();
62+
#endif
63+
5864
_ = optionsBuilder
5965
.EnableDetailedErrors(ContextOptions.EnableDetailedErrors)
6066
.EnableSensitiveDataLogging(ContextOptions.EnableSensitiveDataLogging)
6167
.ReplaceService<IModelCacheKeyFactory, IntersectModelCacheKeyFactory>()
62-
.UseLoggerFactory(ContextOptions.LoggerFactory)
68+
.UseLoggerFactory(loggerFactory)
6369
.UseQueryTrackingBehavior(queryTrackingBehavior);
6470

6571
var connectionString = ConnectionStringBuilder.ConnectionString;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Intersect.Logging;
2+
using Intersect.Reflection;
3+
using Microsoft.Extensions.Logging;
4+
using ILogger = Microsoft.Extensions.Logging.ILogger;
5+
6+
namespace Intersect.Server.Database;
7+
8+
internal sealed class IntersectLoggerFactory : ILoggerFactory
9+
{
10+
private readonly DbLoggerProvider _loggerProvider = new(Log.Default);
11+
12+
public void Dispose()
13+
{
14+
}
15+
16+
public void AddProvider(ILoggerProvider provider)
17+
{
18+
Log.Warn($"Tried to add provider but this is not implemented: {provider.GetFullishName()}");
19+
}
20+
21+
public ILogger CreateLogger(string categoryName)
22+
{
23+
return _loggerProvider.CreateLogger(categoryName);
24+
}
25+
}

0 commit comments

Comments
 (0)