[英]NLog.config is not loaded in asp.net core 2.1 project?
I have the following NLog.Config 我有以下NLog.Config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="On" internalLogFile="c:\temp\nlog-internal.log">
<targets>
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="f" />
</rules>
</nlog>
And then i have followed the following tutorial But i replaced 然后我遵循了以下教程,但是我替换了
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
})
.UseNLog() // NLog: setup NLog for Dependency injection
.Build();
with 与
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(LogLevel.Trace);
})
.UseNLog();
But nothing is written to the specified file or the internal log no matter what i do. 但是无论我做什么,都不会写入指定的文件或内部日志。
I have also tried to quickwatch NLog.Web.NLogBuilder.ConfigureNLog("nlog.config")
and it seems no rules or targets are loaded? 我还尝试过快速监视
NLog.Web.NLogBuilder.ConfigureNLog("nlog.config")
,似乎没有加载任何规则或目标?
I have also verified that nlog.config exists in the build directory bin\\Debug\\netcoreapp2.1\\
and as the right content. 我还验证了nlog.config在构建目录
bin\\Debug\\netcoreapp2.1\\
中是否存在,并且是否正确。
I have also tried to put the absolute path to the file in the NLog.Web.NLogBuilder.ConfigureNLog
but that didn't help. 我也曾尝试将文件的绝对路径放在
NLog.Web.NLogBuilder.ConfigureNLog
但这无济于事。
internalLogLevel="on"
should be internalLogLevel="Trace"
. internalLogLevel="on"
应该是internalLogLevel="Trace"
。
You can add the option throwConfigExceptions="true"
next to throwExceptions="false"
. 您可以在
throwConfigExceptions="true"
旁边添加选项throwConfigExceptions="true"
throwExceptions="false"
。 It will help you track down errors in the NLog.config. 这将帮助您在NLog.config中查找错误。 It is actually a good idea to have
throwConfigExceptions="true"
even when in production environments (Unlike throwExceptions="true"
, which should only be used for unit-testing of NLog) 它实际上是有一个好主意
throwConfigExceptions="true"
,即使在生产环境中(不同于throwExceptions="true"
,这应该只用于NLOG的单元测试)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.