mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-03 09:24:16 +02:00
WIP
This commit is contained in:
38
API/Schema/TrangaBaseContext.cs
Normal file
38
API/Schema/TrangaBaseContext.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using log4net;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
|
||||
namespace API.Schema;
|
||||
|
||||
public abstract class TrangaBaseContext<T> : DbContext where T : DbContext
|
||||
{
|
||||
private ILog Log { get; init; }
|
||||
|
||||
protected TrangaBaseContext(DbContextOptions<T> options) : base(options)
|
||||
{
|
||||
this.Log = LogManager.GetLogger(GetType());
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
optionsBuilder.LogTo(s =>
|
||||
{
|
||||
Log.Debug(s);
|
||||
}, Array.Empty<string>(), LogLevel.Warning, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category | DbContextLoggerOptions.UtcTime);
|
||||
}
|
||||
|
||||
internal async Task<string?> Sync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await this.SaveChangesAsync();
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(null, e);
|
||||
return e.Message;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user