Nlog配置简单比较简单,相比较Log4net有点重量级(大型项目个人推荐用它,毕竟可支持分布式日志收集),当然他们都是很犀利的日志库(http://stackoverflow.com/questions/710863/log4net-vs-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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
<!--自定义规则变量 https://github.com/nlog/NLog/wiki/Configuration-file#variables-->
<variable name="appname" value="RedisTest"/>
<variable name="appversion" value="1.0"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets async="true">
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Configuration-file
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!--<target name="logfile" xsi:type="File" fileName="${basedir}/log/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" />-->
<target name="asyncFile" xsi:type="AsyncWrapper">
<target name="logfile" xsi:type="File" fileName="${basedir}/log/${shortdate}.log" />
</target>
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Debug" writeTo="asyncFile" final="true" />
<logger name="*" minlevel="Info" writeTo="asyncFile" />
</rules>
</nlog>