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>
    

      

  • 相关阅读:
    Compiere中的树
    Compiere 模型构建
    LSMW魔鬼教程
    Compiere 因翻译工作没有完成,所以现在系统中的所有帮助去掉
    插入、更新扩展字段
    SAPscript Forms 教程
    SAP ABAP 效率测试
    批量更新数据表
    月份的描述表T247
    SAP 程序下载工具
  • 原文地址:https://www.cnblogs.com/iframe/p/7609380.html
Copyright © 2011-2022 走看看