也许我误解了你的问题,但像下面这样的结构不回答你的问题吗?
public static void Setup(IUnityContainer container, bool logDebug)
{
LogEventLevel level = logDebug ? LogEventLevel.Debug : LogEventLevel.Info.
container.RegisterFactory<ILogger>(_ => new LoggerConfiguration()
.WriteTo.Console()
.MinimumLevel.Is(level)
.CreateLogger(),
new SingletonLifetimeManager());
}
或者,或者:
public static void Setup(IUnityContainer container, bool logDebug)
{
LogEventLevel level = logDebug ? LogEventLevel.Debug : LogEventLevel.Info.
container.RegisterFactory<ILogger>(_ =>
{
var config = new LoggerConfiguration().WriteTo.Console();
if (logDebug) config = config.MinimumLevel.Is(level);
return config.CreateLogger();
},
new SingletonLifetimeManager());
}