更新框架

This commit is contained in:
chfei committed 2026-10-27 14:35:03 +08:00
1 parent ef50fa0620
commit 84b28f9672
72 files changed
+2222 -282

No files matched your search

@@ -0,0 +1,17 @@
using MAX.Core.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MAX.Framework.Interfaces
{
public interface IFolderConfig : ISingletonDependency
{
string ConfigFolder { get; }
string DataFolder { get; }
string LoggingFolder { get; }
string CacheFolder { get; }
}
}
+26 -12
View File
@@ -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;
@@ -150,12 +150,18 @@ public class AutofacContainerExtension : IContainerExtension<IContainer>, IConta
public IContainerRegistry RegisterSingleton(Type type, Func<object> factoryMethod)
{
throw new NotImplementedException();
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(factoryMethod);
Builder.Register(_ => factoryMethod()).As(type).SingleInstance();
return this;
}
public IContainerRegistry RegisterSingleton(Type type, Func<IContainerProvider, object> factoryMethod)
{
throw new NotImplementedException();
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(factoryMethod);
Builder.Register(_ => factoryMethod(this)).As(type).SingleInstance();
return this;
}
public object Resolve(Type type)
@@ -192,12 +198,18 @@ public class AutofacContainerExtension : IContainerExtension<IContainer>, IConta
public IContainerRegistry Register(Type type, Func<object> factoryMethod)
{
throw new NotImplementedException();
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(factoryMethod);
Builder.Register(_ => factoryMethod()).As(type);
return this;
}
public IContainerRegistry Register(Type type, Func<IContainerProvider, object> factoryMethod)
{
throw new NotImplementedException();
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(factoryMethod);
Builder.Register(_ => factoryMethod(this)).As(type);
return this;
}
public IContainerRegistry RegisterMany(Type type, params Type[] serviceTypes)
{
@@ -320,4 +332,4 @@ public class AutofacContainerExtension : IContainerExtension<IContainer>, IConta
}
}
}
}
+1 -1
View File
@@ -24,7 +24,7 @@ public class Startup : IStartup
public void Register(ContainerBuilder builder)
{
builder.RegisterInstance(NLogger.Instance).As<ILoggerFacade>().SingleInstance();
//builder.RegisterInstance(NLogger.Instance).As<ILoggerFacade>().SingleInstance();
#region 注册所有IOC接口