NLOG
NLOG.EXTENTIOSNS.LOGGING
.net framework用1.0.2
.net core 查文档
创建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">
<variable name="logLayout"
value="Logger:${logger}${newline}Date:${longdate} Level:${uppercase:${level}}${newline}Message:---------------------------------${newline}${message} ${newline}${onexception:Exception:${exception:format=toString}${newline}}-------------------------------------${newline}" />
<targets>
<!--<target name="console" xsi:type="Console" />-->
<target name="asyncFile" xsi:type="AsyncWrapper">
<target name="log_file" xsi:type="File"
fileName="${basedir}/logs/esl-${shortdate}.txt"
layout="${logLayout}"
archiveFileName="${basedir}/archives/${shortdate}-{#####}.txt"
archiveAboveSize="10240000"
archiveNumbering="Sequence"
concurrentWrites="false"
keepFileOpen="true"
encoding="utf-8"
openFileCacheTimeout="30"/>
</target>
</targets>
<rules>
<!--<logger name="*" minlevel="Debug" writeTo="console" />-->
<logger name="*" minlevel="Debug" writeTo="asyncFile" />
</rules>
</nlog>
using NLog;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();