[英]Configuring Nlog for asp.net core 2.02
I am trying to get NLog working in my asp.net core web api 2 which returns json but I am wanting to get loggin in for tracing use etc. 我正在尝试使NLog在我的asp.net核心Web API 2中工作,该API返回json,但我想获取loggin以进行跟踪使用等。
I have setup my nlog.config as per below 我已经按照以下步骤设置了我的nlog.config
<?xml version="1.0"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Warn"
internalLogFile="c:\temp\internal-nlog.txt">
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
<targets>
<target name="allfile" xsi:type="File"
fileName="${basedir}\logs\GDStationaryNetCore\${shortdate}.log"
encoding="utf-8"
layout="[${longdate}][${machinename}][${level}] ${message} ${exception}" />
</targets>
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
<!--Skip Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
</rules>
</nlog>
Then I changed my configure section in my startup to be as follows. 然后,将启动时的配置部分更改如下。
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, LoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
env.ConfigureNLog("nlog.config");
// make sure Chinese chars don't fk up
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
//add NLog to ASP.NET Core
loggerFactory.AddNLog();
//add NLog.Web
app.AddNLogWeb();
//needed for non-NETSTANDARD platforms: configure nlog.config in your project root. NB: you need NLog.Web.AspNetCore package for this.
env.ConfigureNLog("nlog.config");
app.UseMvc();
}
But When I try to compile it gives the following 但是当我尝试编译时,它给出了以下内容
app.AddNLogWeb(); app.AddNLogWeb(); is obseleet use use UseNLog instead 过时了,请改用UseNLog
But when i try to find it on the app. 但是,当我尝试在应用程序上找到它时。 it is not there hope someone can help, 那里不是希望有人可以帮助,
AddNLogWeb is obsolete in nlog AddNLogWeb在nlog中已过时
see: https://github.com/NLog/NLog.Web/blob/44f29fe12569846fa784f20a34726b82ade6526b/NLog.Web.AspNetCore/AspNetExtensions.cs#L29 参见: https : //github.com/NLog/NLog.Web/blob/44f29fe12569846fa784f20a34726b82ade6526b/NLog.Web.AspNetCore/AspNetExtensions.cs#L29
use UseNLog: 使用UseNLog:
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.