配置文件所有內容:app
<?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"
autoReload="true"
internalLogLevel="Warn"
internalLogFile="internal-nlog.txt">測試
<!--define various log targets-->
<targets>
<target name="file" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target xsi:type="File" fileName="${basedir}/logs/${shortdate}.txt" layout="${longdate} ${level:uppercase=true} ${event-context:item=Action} ${message} ${event-context:item=Amount} ${stacktrace}" />
</target>ui
</targets>spa
<rules>
<logger name="*" minlevel="Info" writeTo="file" />
</rules>插件
</nlog>日誌
重點內容:code
<targets>
<target xsi:type="File" name="LogFile" fileName="${basedir}/logs/${shortdate}-${level}.txt"
layout="${longdate}|${uppercase:${level}}|${message} ${exception}" />
</targets>xml
<rules>
<logger name="*" minlevel="Debug" writeTo="LogFile" />
</rules>blog
1 public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory loggerFactory) 2 { 3 /*使用NLog*/ 4 loggerFactory.AddNLog(); 5 env.ConfigureNLog("NLog.config"); 6 7 app.UseStaticFiles(); 8 9 app.UseMvc(routes => 10 { 11 routes.MapRoute( 12 name: "default", 13 template: "{controller=Home}/{action=Index}/{id?}"); 14 }); 15 }
static Logger logger = LogManager.GetCurrentClassLogger(); .... logger.Info("NLog日誌測試" + DateTime.Now);