更新框架
This commit is contained in:
1 parent
ef50fa0620
commit
84b28f9672
72 files changed
+2222
-282
No files matched your search
@@ -1,28 +1,42 @@
|
||||
using MAX.Core.Infrastructure;
|
||||
using MAX.Core.DependencyInjection;
|
||||
using MAX.Core.Infrastructure;
|
||||
using MAX.Core.Logger;
|
||||
using MAX.Framework.Interfaces;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
using System;
|
||||
using LLogLevel = MAX.Core.Logger.LogLevel;
|
||||
using NLogLevel = NLog.LogLevel;
|
||||
|
||||
namespace MAX.Framework.Logger;
|
||||
|
||||
public class NLogger : SingleInstance<NLogger>, ILoggerFacade
|
||||
public class NLogger : ILoggerFacade, ISingletonDependency
|
||||
{
|
||||
private readonly ILogger _log;
|
||||
|
||||
private NLogger()
|
||||
public static ILoggerFacade Instance => LazyServiceProvider.Instance.LazyGetService<ILoggerFacade>();
|
||||
public NLogger(IFolderConfig folderConfig)
|
||||
{
|
||||
//Target target = new FileTarget("log1")
|
||||
//{
|
||||
// FileName = $"{FolderConfig.LoggingFolder}/{DateTime.Now:yyyy-MM-dd}.log",
|
||||
//};
|
||||
//LoggingConfiguration config = new();
|
||||
//config.AddRule(NLogLevel.Debug, NLogLevel.Fatal, target);
|
||||
|
||||
//LogManager.Configuration = config;
|
||||
ArgumentNullException.ThrowIfNull(folderConfig);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(folderConfig.LoggingFolder);
|
||||
lock (ConfigurationLock)
|
||||
{
|
||||
// 使用进程上下文,让 XML 配置及其自动重载共用宿主的目录约定。
|
||||
GlobalDiagnosticsContext.Set("LoggingFolder", folderConfig.LoggingFolder);
|
||||
if (LogManager.Configuration == null)
|
||||
{
|
||||
var target = new FileTarget("application")
|
||||
{
|
||||
FileName = System.IO.Path.Combine(folderConfig.LoggingFolder, "${shortdate}.log"),
|
||||
};
|
||||
var config = new LoggingConfiguration();
|
||||
config.AddRule(NLogLevel.Debug, NLogLevel.Fatal, target);
|
||||
LogManager.Configuration = config;
|
||||
}
|
||||
}
|
||||
_log = LogManager.GetLogger("GlobalLogger");
|
||||
}
|
||||
private static readonly object ConfigurationLock = new();
|
||||
|
||||
public bool IsDebugEnabled { get; private set; } = true;
|
||||
|
||||
|
||||
Reference in new issue
Block a user