You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.4 KiB
C#

using Serilog.Context;
using SqlSugar;
using System;
using System.Collections.Generic;
namespace EntrustSettle.Common.LogHelper;
public class LogContextExtension : IDisposable
{
private readonly Stack<IDisposable> _disposableStack = new Stack<IDisposable>();
public static LogContextExtension Create => new();
public void AddStock(IDisposable disposable)
{
_disposableStack.Push(disposable);
}
public IDisposable SqlAopPushProperty(ISqlSugarClient db)
{
AddStock(LogContext.PushProperty(LogContextStatic.LogSource, LogContextStatic.AopSql));
AddStock(LogContext.PushProperty(LogContextStatic.SqlOutToConsole,
AppSettings.app(new string[] { "AppSettings", "SqlAOP", "LogToConsole", "Enabled" }).ObjToBool()));
AddStock(LogContext.PushProperty(LogContextStatic.SqlOutToFile,
AppSettings.app(new string[] { "AppSettings", "SqlAOP", "LogToFile", "Enabled" }).ObjToBool()));
AddStock(LogContext.PushProperty(LogContextStatic.OutToDb,
AppSettings.app(new string[] { "AppSettings", "SqlAOP", "LogToDB", "Enabled" }).ObjToBool()));
AddStock(LogContext.PushProperty(LogContextStatic.SugarActionType, db.SugarActionType));
return this;
}
public void Dispose()
{
while (_disposableStack.Count > 0)
{
_disposableStack.Pop().Dispose();
}
}
}