nlog的简单使用
1.nuget 安装 nlog
2.根目录下(与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"
internalLogFile="C:\Temp\NLog.Internal.txt" >
<variable name="logLayout"
value="Logger:${logger}${newline}Date:${longdate} Level:${uppercase:${level}}${newline}Message:${message} ${newline}${onexception:Exception:${exception:format=toString}${newline}}" />
<targets>
<target name="asyncFile" xsi:type="AsyncWrapper">
<target name="log_file" xsi:type="File"
fileName="${basedir}/Logs/${shortdate}/${shortdate}.txt"
layout="${logLayout}"
archiveFileName="${basedir}/archives/${shortdate}-{#####}.txt"
archiveAboveSize="102400"
archiveNumbering="Sequence"
concurrentWrites="false"
keepFileOpen="true"
encoding="utf-8"
openFileCacheTimeout="30"/>
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="asyncFile" />
</rules>
</nlog>
3.代码中使用