NLOG配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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">

<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!-- add your targets here -->

<!--
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
<!--说明:
xsi:type="File"指定输出到文件类型;
name ="file_info"指定target的名字;
fileName="${basedir}/Logs/NlogBlog_${level}_${shortdate}.txt"指定输出文件的具体名。
其中${basedir}的意思是程序所在的路径; ${level}的意思是日志的等级; ${shortdate}的意思是日期(具体到日)"
layout="${longdate} ${message}"指定输出文件内容的样式(可自由定义);
其中${longdate}的意思是日期(具体到毫秒),${message}是你具体要输出的内容。
-->
<target xsi:type="File" name ="file_info" fileName="${basedir}/Logs/NlogBuyLimit_${level}_${shortdate}.txt"
layout="${longdate} ${message}" encoding="UTF-8"/>
<target xsi:type="File" name ="file_info1" fileName="${basedir}/Logs/NlogBuyStop_${level}_${shortdate}.txt"
layout="${longdate} ${message}" encoding="UTF-8"/>
<target xsi:type="File" name ="file_info2" fileName="${basedir}/Logs/NlogSellLimit_${level}_${shortdate}.txt"
layout="${longdate} ${message}" encoding="UTF-8"/>
<target xsi:type="File" name ="file_info3" fileName="${basedir}/Logs/NlogSellStop_${level}_${shortdate}.txt"
layout="${longdate} ${message}" encoding="UTF-8"/>


<target xsi:type="File" name ="file_debug" fileName="${basedir}/Logs/NlogBlog_${level}_${shortdate}.txt"
layout="${longdate} ${message}" encoding="UTF-8"/>
<target xsi:type="File" name ="file_warn" fileName="${basedir}/Logs/NlogBlog_${level}_${shortdate}.txt"
layout="${longdate} ${message}" encoding="UTF-8"/>
<target xsi:type="File" name ="file_error" fileName="${basedir}/Logs/NlogBlog_${level}_${shortdate}.txt"
layout="${longdate} ${message}" encoding="UTF-8"/>
<target xsi:type="File" name ="file_trace" fileName="${basedir}/Logs/NlogBlog_${level}_${shortdate}.txt"
layout="${longdate} ${message}" encoding="UTF-8"/>

</targets>

<rules>
<!-- add your logging rules here -->

<!--
<logger name="*" minlevel="Trace" writeTo="f" />
-->
<logger name="A" levels="Info" writeTo="file_info"/>
<logger name="B" levels="Info" writeTo="file_info1"/>
<logger name="C" levels="Info" writeTo="file_info2"/>
<logger name="D" levels="Info" writeTo="file_info3"/>
<logger name="*" levels="Debug" writeTo="file_debug"/>
<logger name="*" levels="Warn" writeTo="file_warn"/>
<logger name="*" levels="Error" writeTo="file_error"/>
<logger name="*" levels="Trace" writeTo="file_trace"/>
</rules>
</nlog>

 

  private static NLog.Logger BuyLimitLog = NLog.LogManager.GetLogger("A");

以上是关于NLOG配置的主要内容,如果未能解决你的问题,请参考以下文章

.Net -- NLog日志框架配置与使用

NLOG配置

NLog学习笔记二:深入学习

常用NLog配置

Nlog配置文件

NLog 缺少带有异步翻转文件配置的日志条目