7.NLog config

Edit

7.1Web.config에 직접 설정

Web.config

<configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog throwConfigExceptions="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
        <target name="LogFile"
        xsi:type="File"
        layout="${longdate} [${uppercase:${level:padding=-5}}] ${message} ${exception:format=tostring}"
        fileName="${basedir}Logs\${var:runtime}\${date:format=yyyyMMdd}.log"
        encoding="UTF-8"
        archiveFileName="${basedir:processDir=true}Logs\archives\${var:runtime}\archive.{#}.log"
        archiveEvery="Day"
        archiveNumbering="Rolling"
        maxArchiveFiles="7"
        header="[Start Logging]"
        footer="[End Logging]${newline}"/>
    </targets>
    <rules>
        <logger name="*" minlevel="Info" writeTo="LogFile"/>
    </rules>
</nlog>

App.config나 web.config 파일에 nlog를 embedded 할 경우 section을 지정

<configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog">
</configSections>

로그 생성 중 예외가 발생했을 경우 출력 옵션

<nlog throwConfigExceptions="true" …………… >

변수 설정

<variable name=”logDir” value=”${basedir}/logs/”>

target 지정 시 출력 layout을 CSV, JSON, XML 혹은 File 형태로 지정 가능

<targets>
<target name="LogFile" 
xsi:type="File" 
        layout="${longdate} [${uppercase:${level:padding=-5}}] ${message} ${exception:format=tostring}" 
        fileName="${basedir}Logs\${var:runtime}\${date:format=yyyyMMdd}.log" 
        encoding="UTF-8"               
        archiveFileName="${basedir:processDir=true}Logs\archives\${var:runtime}\archive.{#}.log" 
        archiveEvery="Day" 
        archiveNumbering="Rolling" 
        maxArchiveFiles="7" 
        header="[Start Logging]" 
        footer="[End Logging]${newline}">
</targets>

Rule 설정

<rules>
    <logger name="*" minlevel="Info" writeTo="LogFile">
<logger name="nexacro17.xapi.tx.*" minlevel="Info" writeTo="LogFile">
</rules>

7.2환경 변수 및 XML 설정 참고

Layout 환경 변수

https://nlog-project.org/config/?tab=layout-renderers


XML 설정

https://github.com/nlog/NLog/wiki/Configuration-file#variables