zoukankan      html  css  js  c++  java
  • NLog小记

    NLog安装:

    Install-Package NLog

    NLog配置:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <configSections>
        <section name="nlog" type="NLog.Config.ConfigSectionHandler,NLog" />
      </configSections>
    
      <!--autoReload="true"表示在不重新启动应用程序的情况下,修改配置文件,NLog会自动加载应-->
      <!--NLog内部的日志消息写到应用程序目录下的logs文件夹里的internalLog.txt文件中;(-->
      <nlog autoReload="true" internalLogLevel="Trace" internalLogFile="logs/internalLog.txt">
        <targets>
          <!--文件输出(type="File")-->
          <target name="FileOutput" type="File" fileName="${basedir}/logs/${shortdate}.log"
                  layout="${longdate} ${callsite} ${level}:
                  ${message} ${event-context:item=exception} ${stacktrace} ${event-context:item=stacktrace}" />
          <!--控制台输出(type="File")-->
          <target name="ConsoleOutput" type="Console" layout="${date:format=yyyy-MM-dd HHmmss} ${callsite} ${level} ${message}"></target>
        </targets>
        <rules>
          <!--<logger name="Test" minlevel="Debug" maxlevel="Error" writeTo="FileOutput,ConsoleOutput" />-->
          <logger name="*" minlevel="Debug" maxlevel="Error" writeTo="FileOutput,ConsoleOutput" />
        </rules>
      </nlog>
    
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>
    </configuration>
    View Code

    NLog使用:

     private static readonly Logger Logger = LogManager.GetCurrentClassLogger();//LogManager.GetLogger("Test");
            static void Main(string[] args)
            {
                Logger.Trace("This is Trace");
                Logger.Debug("This is Debug");
                Logger.Info("This is Info");
                Logger.Error("This is Error");
                Logger.Fatal("This is Fatal");
    
                Console.ReadLine();
            }
  • 相关阅读:
    自动安装rpm依赖
    goroutine上下文contxt语法
    goroutine 上下文用法
    Template Method 模式
    设计模式2--设计原则
    centos7关机自动进行远程服务器备份
    实用工具使用
    剑指offer python版 滑动窗口的最大值
    剑指offer python版 左旋转字符串
    剑指offer python版 翻转单词顺序
  • 原文地址:https://www.cnblogs.com/kuangxiangnice/p/6373775.html
Copyright © 2011-2022 走看看