Nlog简单使用

本文介绍了Nlog日志库的简易配置过程,相对于Log4net,Nlog更轻量级,适合快速集成。虽然Log4net在大型项目中表现出色,支持分布式日志收集,但Nlog的配置更加直观易懂。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Nlog配置简单比较简单,相比较Log4net有点重量级(大型项目个人推荐用它,毕竟可支持分布式日志收集),当然他们都是很犀利的日志库(http://stackoverflow.com/questions/710863/log4net-vs-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"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >

  <!--自定义规则变量 https://github.com/nlog/NLog/wiki/Configuration-file#variables-->
  <variable name="appname" value="RedisTest"/>
  <variable name="appversion" value="1.0"/>

  <!-- 
  See https://github.com/nlog/nlog/wiki/Configuration-file 
  for information on customizing logging rules and outputs.
   -->
  <targets async="true">
    <!-- 
    add your targets here 
    See https://github.com/nlog/NLog/wiki/Configuration-file
    See https://github.com/nlog/NLog/wiki/Targets for possible targets.
    See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
    -->
    <!--<target name="logfile" xsi:type="File" fileName="${basedir}/log/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" />-->
    <target name="asyncFile" xsi:type="AsyncWrapper">
      <target name="logfile" xsi:type="File" fileName="${basedir}/log/${shortdate}.log" />
    </target>
  </targets>

  <rules>
    <!-- add your logging rules here -->
    <logger name="*" minlevel="Debug" writeTo="asyncFile" final="true" />
    <logger name="*" minlevel="Info" writeTo="asyncFile" />
  </rules>
</nlog>


详细可看github上说明,另外可参阅此篇,还蛮详细的: http://www.cnblogs.com/TianFang/p/4003749.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值