zoukankan      html  css  js  c++  java
  • .net core 使用 Nlog 配置文件

    nlog.config文件

    安装nuget包:

    NLog.Web.AspNetCore

    配置开始

    <?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"
    autoReload="true"
    internalLogLevel="Info"
    internalLogFile="Logs/nlog.log" >

    <!-- enable asp.net core layout renderers -->
    <extensions>
    <add assembly="NLog.Web.AspNetCore"/>
    </extensions>

    <!-- optional, add some variabeles
    https://github.com/nlog/NLog/wiki/Configuration-file#variables
    -->
    <!--<variable name="myvar" value="myvalue"/>-->

    <!--
    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/Targets for possible targets.
    See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
    -->

    <!--Writing events to the a file with the date in the filename.-->
    <target xsi:type="File" name="errorLogFileTarget" fileName="${basedir}/Logs/nlogs/errors/${shortdate}.log"
    layout="${longdate} ${logger} ${uppercase:${level}} ${message} ${newline} ${exception:format=ToString}" />
    <target xsi:type="File" name="infoLogFileTarget" fileName="${basedir}/Logs/nlogs/infos/${shortdate}.log"
    layout="${longdate} ${logger} ${uppercase:${level}} ${message}" />
    <target xsi:type="File" name="debugLogFileTarget" fileName="${basedir}/Logs/nlogs/debugs/${shortdate}.log"
    layout="${longdate} ${logger} ${uppercase:${level}} ${message}" />
    <target xsi:type="File" name="warnLogFileTarget" fileName="${basedir}/Logs/nlogs/warns/${shortdate}.log"
    layout="${longdate} ${logger} ${uppercase:${level}} ${message}" />
    <target xsi:type="File" name="fatalLogFileTarget" fileName="${basedir}/Logs/nlogs/fatals/${shortdate}.log"
    layout="${longdate} ${logger} ${uppercase:${level}} ${message}" />
    <target xsi:type="File" name="traceLogFileTarget" fileName="${basedir}/Logs/nlogs/traces/${shortdate}.log"
    layout="${longdate} ${logger} ${uppercase:${level}} ${message}" />

    <target xsi:type="Mail" name="errorMailTarget"
    smtpServer="smtp.exmail.qq.com"
    smtpAuthentication="Basic"
    smtpPassword=""
    smtpUserName=""
    enableSsl="true"
    addNewLines="true"
    from=""
    to=""
    subject="Api Error"
    header="============================ Api Error Begin ============================="
    body="${longdate} ${logger} ${uppercase:${level}} ${message} ${newline} ${exception:format=ToString}"
    footer="============================ Api Error End ============================="
    />

    </targets>

    <rules>
    <!-- add your logging rules here -->
    <!--Write all events with minimal level of Trace-->
    <logger name="*" minlevel="Debug" maxlevel="Debug" writeTo="debugLogFileTarget" />
    <logger name="*" minlevel="Info" maxlevel="Info" writeTo="infoLogFileTarget" />
    <logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="warnLogFileTarget" />
    <logger name="*" minlevel="Error" maxlevel="Error" writeTo="errorLogFileTarget" />
    <logger name="*" minlevel="Fatal" maxlevel="Fatal" writeTo="fatalLogFileTarget" />
    <logger name="*" minlevel="Trace" maxlevel="Trace" writeTo="traceLogFileTarget" />
    <!--<logger name="*" minlevel="Error" maxlevel="Error" writeTo="errorMailTarget" />-->
    </rules>
    </nlog>

    配置结束

  • 相关阅读:
    BZOJ 2724: [Violet 6]蒲公英
    codeforces Lightsabers (hard)
    BZOJ 3884: 上帝与集合的正确用法
    BZOJ 4809: 皇后
    python的变量类型(Day6)
    Python集合方法整理(Day9)
    基本运算符与流程控制(Day5)
    基本数据类型(Day4)
    第一个Python程序(Day3)
    操作系统(Day2.5)
  • 原文地址:https://www.cnblogs.com/jeffhong99/p/14929669.html
Copyright © 2011-2022 走看看