我写一个ASP.NET 2.2的核心服务,即使用Common.Logging和NLOG。
我迷上了Common.Logging,与NLOG,在appsettings.json文件:
"LogConfiguration": {
"factoryAdapter": {
"type": "Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog45",
"arguments": {
"configType": "FILE",
"configFile": "~/nlog.config"
}
}
}
而在Startup.cs我说:
var logConfiguration = new LogConfiguration();
Configuration.GetSection("LogConfiguration").Bind(logConfiguration);
LogManager.Configure(logConfiguration);
当我开始我的服务和代码击中logger.Info,I get a The type initializer for '...' threw an exception
。
对于NLOG这通常意味着没有目标被发现。我用Procmon.exe搜索nlog.config的失败的访问,发现了一个企图为:C:\ Program Files文件\ IIS快递\〜\ nlog.config。
我怎样才能获得IIS Express来寻找nlog.config在内容根?
如图所示拉动请求为什么不这样做:
{
"LogConfiguration": {
"factoryAdapter": {
"type": "Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog45",
"arguments": {
"configType": "INLINE",
}
}
}
}
而让NLOG 4.5加载自己的LoggingConfiguration。
https://github.com/net-commons/common-logging/pull/176
您也可以明确,从想要的位置日志NLog.config:
https://github.com/NLog/NLog/wiki/Explicit-NLog-configuration-loading