您的位置:首页 > 编程语言 > C#

C#Nlog配置文件 万能模板 输出到控制台及文件

2016-07-28 09:22 351 查看
项目中经常用到的配置文件模板,在这里做一下记录,也方便给大家查看,直接上代码:

已用过很多次了。

具体解释,请参考其他文章,网上已经写的很详尽了。

直接拿去使用,不谢:

<?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">

  <targets>

    <target name="console" xsi:type="ColoredConsole"

      layout= "$[${date:format=yyyy-MM-dd HH\:mm\:ss}] [${uppercase:${level}}] [${logger}] [${callsite}]: ${message}"/>

    <target name="file" xsi:type="File"

            fileName="${basedir}/Logs/${date:format=yyyy}/${date:format=MM}/${shortdate}.log"

 layout="[${date:format=yyyy-MM-dd HH\:mm\:ss}] [${uppercase:${level}}] [${callsite}]: ${message}"

     keepFileOpen="false"

     encoding="iso-8859-2" />

  </targets>

  <rules>
    <logger name="*" minlevel="Trace" writeTo="console"/>  
    <logger name="*" minlevel="Trace" writeTo="file" />

  </rules>

</nlog>

说明:LOGS输出在,项目所在文件夹->启动项文件夹->Bin->Debug->LOGS
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息