Files
laatzen/LaaProductionWeb/LaaProductionWeb.Blazor/Components/Logging/Sqlite/SqliteLoggerProvider.cs
T
2025-03-17 16:03:24 +01:00

30 lines
872 B
C#

namespace LaaProductionWeb.Blazor.Components.Logging.Sqlite
{
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Collections.Concurrent;
public class SqliteLoggerProvider(IOptionsMonitor<SqliteLoggerOptions> options) : ILoggerProvider
{
private readonly SqliteLoggingDbContext sqlite = new (options);
private readonly ConcurrentDictionary<string, ILogger> loggers = new ConcurrentDictionary<string, ILogger>();
public ILogger CreateLogger(string type)
{
if (string.IsNullOrWhiteSpace(type))
{
type = "undefined";
}
return this.loggers.GetOrAdd(type, new SqliteLogger(sqlite));
}
public void Dispose()
{
this.loggers.Clear();
this.sqlite.Dispose();
}
}
}