簡體   English   中英

是否在不更改代碼的情況下通過配置支持NLog中Logger的鏈接?

[英]Is chaining of Loggers in NLog supported through configuration without changing the code?

這是我的nlog的配置:

<targets async="true">
    <target name="console" xsi:type="ColoredConsole" useDefaultRowHighlightingRules="false" layout="${date:format=MMM dd, yyyy hh\:mm\:ss.ff tt} | ${level} ${message}" >
    </target>

    <target xsi:type="File" name="app" fileName="logs\quantum_${shortdate}.log"
            layout="${date:universalTime=True:format=MMM dd, yyyy hh\:mm\:ss.ff tt} | ${event-properties:item=EventId_Id} ${uppercase:${level}} | ${message} ${exception:format=message}" />

    <target xsi:type="File" name="errors" fileName="logs\exceptions_${shortdate}.log"
            layout="${date:universalTime=True:format=MMM dd, yyyy hh\:mm\:ss.ff tt} | ${event-properties:item=EventId_Id} ${uppercase:${level}} | ${message} ${exception:format=tostring}" />

    <target xsi:type="File" name="aspcore" fileName="logs\aspcore_${shortdate}.log"
            layout="${date:universalTime=True:format=MMM dd, yyyy hh\:mm\:ss.ff tt} | ${event-properties:item=EventId_Id} | ${uppercase:${level}} | ${message} ${exception:format=tostring} | url: ${aspnet-request-url} | action: ${aspnet-mvc-action}" />
</targets>

<rules>
    <logger name="app" minlevel="Trace" writeTo="app,console" />
    <logger name ="appErrors" minlevel="Error" writeTo="errors" />
    <logger name="Microsoft.*" maxLevel="Error" writeTo="aspcore"/> 
</rules>

現在,我想鏈接記錄器,而無需根據條件更改代碼。 為了登錄到應用程序 ,但當出現異常時, 應用程序應將其傳遞給appErrors ,該錯誤實際上可以記錄完整的異常。

因此最終應用程序僅包含異常消息。 而appError將包含發生的所有異常的詳細信息。 是否可以在nlog中使用某些配置?

看來您已經知道了。 我不知道appErrors應該做什么,但是您可以這樣做:

<rules>
    <logger name="app" minlevel="Trace" writeTo="app,console" />
    <logger name="app" minlevel="Error" writeTo="errors" />
    <logger name="Microsoft.*" maxLevel="Error" writeTo="aspcore"/> 
</rules>

因此,來自LogLevel> = Error的應用程序的所有日志都將同時存儲在logs\\quantum_${shortdate}.log並且(僅錯誤日志)將同時包含在logs\\exceptions_${shortdate}.log

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM