c#语言使用的日志比较多,比如:Log4、NLog等,今天我就简单随笔记录哈NLog的使用。
1.NLog的安装:
直接在VS编译器中打开程序包管理器,输入Install-Package NLogin添加进行自己的项目;
VS程序包管理器请查看 http://blog.csdn.net/doris_d/article/details/46558351
2.安装NLog配置文件:
同上在程序包管理器中加入Install-Package NLogin.config;
3.添加完成之后,目录大致如下:
4.打开配置文件进行配置
1 <targets async="true"> 2 <!-- 3 add your targets here 4 See https://github.com/nlog/NLog/wiki/Targets for possible targets. 5 See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers. 6 --> 7 <target xsi:type="File" name="file_info" 8 fileName="${basedir}/Logs/Info/info_${shortdate}.txt" 9 layout="${message}" 10 archiveAboveSize="10240" 11 archiveNumbering="Sequence" 12 concurrentWrites="true" 13 keepFileOpen="false" 14 encoding="iso-8859-2" 15 /> 16 <target xsi:type="File" name="file_debug" 17 fileName="${basedir}/Logs/Debug/debug_${shortdate}.txt" 18 layout="${message}" 19 archiveAboveSize="10240" 20 archiveNumbering="Sequence" 21 concurrentWrites="true" 22 keepFileOpen="false" 23 encoding="iso-8859-2" 24 /> 25 <!-- 26 Write events to a file with the date in the filename. 27 <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" 28 layout="${longdate} ${uppercase:${level}} ${message}" /> 29 --> 30 </targets> 31 <rules> 32 <logger name="*" level="Info" writeTo="file_info"></logger> 33 <logger name="*" level="Debug" writeTo="file_debug"></logger> 34 </rules>