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>
    

      

  • 相关阅读:
    centos 安装php7.0.2
    Yii restful api跨域
    为何我们总难听进别人的话
    workerman 7272端口被占用
    linux本地机上传文件到服务器
    linux命令-查找所有文件中包含某个字符串
    workerman程序调试
    关于吃苦
    哈夫曼编码
    链表的游标实现
  • 原文地址:https://www.cnblogs.com/iframe/p/7609380.html
Copyright © 2011-2022 走看看