zoukankan      html  css  js  c++  java
  • 在C#中winform程序中应用nlog日志工具

    在C#中winform程序中应用nlog日志工具,配置文件简单应用.

    文件名 nlog.config,请注意修改属性为"始终复制",发布时候容易遇到不存在文件的错误提示.

    通过NuGet添加对应framework版本的nlog工具,如果framework切换版本,需要卸载之后,重新安装.

    简单配置的nlog.config文件.

    项目实际在用:会在bin文件夹下创建logs文件夹,然后生成对应的log文件,可以用记事本打开查看日志内容.

    内容如下:

    样式1:

    <?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 async="true" maxarchivefiles="2">
        <target  name="log_file" xsi:type="File"  fileName="${basedir}/logs/${date:format=yyyyMMdd}.log"
                layout="[============================${newline}${date} ${appdomain}  ${logger} ${level}${newline}${message}${newline}${exception}]"/>
      </targets>
      <rules>
        <logger name="*" minlevel="trace"  writeTo="log_file"></logger>
      </rules>
    </nlog>
    

    样式2:

    <?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 async="true" maxarchivefiles="2">
        <target  name="log_file" xsi:type="File"  fileName="${basedir}/logs/${date:format=yyyyMMdd}.log"
                layout="[==${date} ${appdomain}  ${logger} ${level}==]${newline}${message}${newline}${exception}${newline}"/>
      </targets>
      <rules>
        <logger name="*" minlevel="trace"  writeTo="log_file"></logger>
      </rules>
    </nlog>
    

      

  • 相关阅读:
    HashTable、HashSet和Dictionary的区别
    CCF_ 201312-3_最大的矩形
    CCF_ 201312-2_ISBN号码
    CCF_201312-1_出现次数最多的数
    CCF_ 201509-2_日期计算
    CCF_ 201512-3_画图
    CCF_ 201512-2_消除类游戏
    CCF_ 201409-2_画图
    CCF_201409-1_相邻数对
    CCF_ 201412-1_门禁系统
  • 原文地址:https://www.cnblogs.com/iframe/p/7609380.html
Copyright © 2011-2022 走看看