LoginSignup
3
2

More than 5 years have passed since last update.

NLog.config

Last updated at Posted at 2017-01-12

NLog.config

とりあえず、今使用している設定をメモ

NLog.config
<?xml version="1.0" encoding="utf-8" ?>
<!--
  フォーマット等の詳細は http://nlog-project.org/ を参照
  プロジェクト⇒プロパティ⇒ビルドイベント⇒ビルド後に実行するコマンドライン
  copy $(ProjectDir)NLog.config $(TargetDir)

  以下ではうまくいかない・・・ XCOPY の終了コードが '2'になることがあるため。
  xcopy $(ProjectDir)NLog.config $(TargetDir) /D

  以下ではうまくいかない・・・ ROBOCOPY のコピー時の終了コードが'1'のため。
  ROBOCOPY $(ProjectDir) $(TargetDir) NLog.config /XO
-->
<nlog autoReload="true"
      xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <variable name="logFilename" value="${replace:searchFor=\.vshost$:replaceWith=\.log:regex=true:ignoreCase=true:inner=${processname}}"/>
  <variable name="logDir" value="${basedir:dir=../logs/}"/>
  <variable name="logFile" value="${logDir}${logFilename}"/>
  <targets async="true">
    <target name="console"
            xsi:type="Console"
            layout='${time} ${level:uppercase=true} "${message}"' />
    <target name="Debugger"
            xsi:type="Debugger"
            layout='${time} ${level:uppercase=true} "${message}"' />
    <target name ="logfile"
            xsi:type="File"
            filename="${logDir}${logFilename}"
            archiveFileName="${logDir}${logFilename}.{#}"
            archiveEvery="Day"
            archiveNumbering="Rolling"
            maxArchiveFiles="7"
            keepFileOpen="false"
            header="# -- encoding:utf-8 -- UTF-8${newline}hahaha"
            layout='${counter:padding=8} ${longdate} [${threadid:padding=8}] [${uppercase:${level:padding=-5}}] ${callsite}:${callsite-linenumber} ${message} ${exception:format=tostring}'
            encoding="UTF-8" />
    <target name ="InfoLogFile"
            xsi:type="File"
            filename="${logDir}${logFilename}"
            archiveFileName="${logDir}${logFilename}.{#}"
            archiveEvery="Day"
            archiveNumbering="Rolling"
            maxArchiveFiles="7"
            keepFileOpen="false"
            encoding="utf-8" >
      <layout xsi:type="CSVLayout">
        <!-- CSV Options -->
        <!--         <header># - - encoding:utf-8 - - UTF-8</header>-->
        <quoting>Auto</quoting>
        <withHeader>True</withHeader>
        <delimiter>Tab</delimiter>
        <column name="Counter" layout="${counter:padding=8}" />
        <column name="Date" layout="${longdate}" />
        <column name="ThreadName:id" layout="[${threadname}:${threadid}]" />
        <column name="Level" layout="[${uppercase:${level:padding=-5}}]" />
        <column name="Message" layout="${message}" />
        <column name="CallSite:LineNo" layout=" " />
        <column name="Exception" layout="${exception:format=tostring}" />
      </layout>
    </target>
    <target name ="FatalLogFile"
            xsi:type="File"
            filename="${logDir}${logFilename}"
            archiveFileName="${logDir}${logFilename}.{#}"
            archiveEvery="Day"
            archiveNumbering="Rolling"
            maxArchiveFiles="7"
            keepFileOpen="false"
            encoding="utf-8" >
      <layout xsi:type="CSVLayout">
        <!-- CSV Options -->
        <!--<header># - - encoding:utf-8 - - UTF-8</header>-->
        <quoting>Auto</quoting>
        <withHeader>True</withHeader>
        <delimiter>Tab</delimiter>
        <column name="Counter" layout="${counter:padding=8}" />
        <column name="Date" layout="${longdate}" />
        <column name="ThreadName:id" layout="[${threadname}:${threadid}]" />
        <column name="Level" layout="[${uppercase:${level:padding=-5}}]" />
        <column name="Message" layout="${message}" />
        <column name="CallSite:LineNo" layout="${callsite}:${callsite-linenumber}" />
        <column name="Exception" layout="${exception:format=tostring}" />
      </layout>
    </target>
  </targets>
  <rules>
    <logger name="*" minlevel="Trace" writeTo="Debugger" />
<!--
    <logger name="*" minlevel="Warn" writeTo="FatalLogFile" />
    <logger name="*" minlevel="Info"  maxlevel="Info" writeTo="InfoLogFile" />
    <logger name="*" minlevel="Debug" maxlevel="Debug" writeTo="InfoLogFile" />
    <logger name="*" minlevel="Trace" maxlevel="Trace" writeTo="InfoLogFile" />
-->
    <logger name="*" minlevel="Trace" writeTo="FatalLogFile" />
  </rules>
</nlog>

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2