Files
2023-07-11 10:00:30 +08:00

25 lines
779 B
C#

namespace Util.Logging.Tests;
/// <summary>
/// 日志上下文访问器
/// </summary>
public class LogContextAccessor : ILogContextAccessor {
/// <summary>
/// 日志上下文键名
/// </summary>
public const string LogContextKey = "Util.Logging.LogContext";
/// <summary>
/// 日志上下文
/// </summary>
public LogContext Context {
get {
var slot = System.Threading.Thread.GetNamedDataSlot( LogContextKey );
return Util.Helpers.Convert.To<LogContext>( System.Threading.Thread.GetData( slot ) );
}
set {
var slot = System.Threading.Thread.GetNamedDataSlot( LogContextKey );
System.Threading.Thread.SetData( slot, value );
}
}
}