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();
            }
  • 相关阅读:
    协程与IO模型
    进程池与线程池
    GIL全局解释器锁
    线程编程
    进程编程
    基于UDP协议的socket
    异常处理
    jquery mobile外部js无法载入问题
    禁用或限制部分WebKit特性
    eval 返回变量值
  • 原文地址:https://www.cnblogs.com/kuangxiangnice/p/6373775.html
Copyright © 2011-2022 走看看