2016-10-12 15 views
1

vb.net(asp.net)アプリケーションで実行時に変数をNLogで更新しようとしても、動作していないようです。しかしNLog - 変数更新(実行時)

NLog.GlobalDiagnosticsContext.Set("Line", "myLine") 

- ログファイル名は、常に「DEBUG.LOG」の代わりに「myLinedebugです:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" 
    autoReload="true" 
    throwExceptions="false" 
    internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"> 


<variable name="DebugInfoLayout" value="[${date:format=MM/dd/yyyy hh\:mm\:ss.fff tt}] [${gdc:item=location}] | ${level} | ${message}" /> 
    <variable name="InfoLayout" value="[${date:format=MM/dd/yyyy hh\:mm\:ss.fff tt}] ${gdc:item=SoftwareName} Version ${gdc:item=SoftwareVersion} - ${message}" /> 
    <variable name="LogLayout" value="[${date:format=MM/dd/yyyy hh\:mm\:ss.fff tt}] ${message}" /> 
    <variable name="logDir" value="C:/Logfiles/" /> 
    <variable name="ArchiveDir" value="C:/Logfiles/Archive" /> 
    <variable name="Line" value="" /> 

    <targets async="false"> 
    <target name="Errors" xsi:type="File" fileName="${logDir}/${var:Line}errors.log" layout="${DebugInfoLayout}" keepFileOpen="false" archiveFileName="${ArchiveDir}/errors_${shortdate}.{##}.log" archiveNumbering="Sequence" archiveEvery="Day" maxArchiveFiles="30" archiveOldFileOnStartup="true" /> 
    <target name="Info" xsi:type="File" fileName="${logDir}/${var:Line}info.log" layout="${InfoLayout}" keepFileOpen="false" archiveFileName="${ArchiveDir}/info_${shortdate}.{##}.log" archiveNumbering="Sequence" archiveEvery="Day" maxArchiveFiles="30"/> 
    <target name="Debug" xsi:type="File" fileName="${logDir}/${var:Line}debug.log" layout="${DebugInfoLayout}" keepFileOpen="false" archiveFileName="${ArchiveDir}/debug_${shortdate}.{##}.log" archiveNumbering="Sequence" archiveEvery="Day" maxArchiveFiles="30" /> 
    </targets> 

    <rules> 
    <logger name="Errors" minlevel="Trace" maxlevel="Fatal" writeTo="Errors" /> 
    <logger name="Info" minlevel="Trace" maxlevel="Warn" writeTo="Info" /> 
    <logger name="Debug" minlevel="Trace" maxlevel="Fatal" writeTo="Debug" /> 
    </rules> 

</nlog> 

私は更新しようとしている変数は「ライン」と呼ばれ、私は次のコードを持っています。ログ"。

答えて

1

代わりの

GlobalDiagnosticsContext.Set("Line", "myLine")` 

使用

LogManager.Configuration.Variables("line") = "myLine" 

GlobalDiagnosticsContextと変数が似た概念を使用していますが、それらは同じではありません。 GlobalDiagnosticsContext${gdc}レンダラーで使用されます。

the docs of ${var}

+0

恐ろしい!!!本当にありがとう。私はそれがgdcの文脈であることを知っていたので、私はそれを逃したとは思えません。ありがとう、ジュリアン。 – Andrew

関連する問題