Nlog日志出坑合集

Posted simonwu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nlog日志出坑合集相关的知识,希望对你有一定的参考价值。

.net core框架下nlog不记录:

1.安装NLog.Web.AspNetCore

2.在Startup.cs文件的方法public void Configure(IApplicationBuilder app, IHostingEnvironment env)中,添加下面一行代码:

env.ConfigureNLog("NLog.config");

 


 

 

Nlog默认配置:

<?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">
  <variable name="logDirectory" value="${basedir}/Logs" />

  <targets async="true">
    <target name="file"
      xsi:type="File"
      layout="${longdate} ${threadid:padding=4} ${level:uppercase=true:padding=5} ${logger:shortName=true} ${message} ${exception:format=tostring}"
      fileName="${logDirectory}/log.txt"
      archiveFileName="${logDirectory}/log.{#}.txt"
      archiveEvery="Day"
      archiveNumbering="Rolling"
      maxArchiveFiles="7"
      concurrentWrites="true"
      createDirs="true"
      autoFlush="true" />
  </targets>

  <rules>
    <logger name="*" minlevel="Trace" writeTo="file" />
  </rules>
</nlog>

 

以上是关于Nlog日志出坑合集的主要内容,如果未能解决你的问题,请参考以下文章