2017-02-13 169 views
2

我正在使用Nlog調試/信息/異常。其工作正常,但問題是當我登錄異常它在新的線上記錄堆棧跟蹤。異常(堆棧跟蹤)在一行

有人能幫助我如何得到它的一條線,佈局我使用:

<target xsi:type="File" name="default" layout="${longdate} -- [${level:uppercase=true}] -- ${message} ${onexception:${newline}EXCEPTION OCCURED\: ${exception:format=ToString}}" 
     fileName="${basedir}/logs/logfile.txt" keepFileOpen="false" 
     archiveFileName="${basedir}/logs/archive/logfile_${shortdate}.{##}.log" 
     archiveNumbering="Sequence" archiveEvery="Day" maxArchiveFiles="30" /> 

我試圖寫一個小觀衆將通過符合閱讀以及log.txt讀取線一些佔位符,所以任何幫助將不勝感激。

+0

如果堆棧跟蹤不強制你,那麼你可以改變'format'到'message' –

+0

您可以擴展NLog並自定義渲染器以按照您的需要編寫日誌。 http://nlog-project.org/2015/06/30/extending-nlog-is-easy.html或https://github.com/NLog/NLog/wiki/Replace-NewLines-Layout-Renderer –

+0

我的答案有效? – Julian

回答

0

ToString格式是帶有換行符的默認.NET格式。你可以用${replace-newlines來代替它們,但它有點冒險。它應該是這樣的:

${replace-newlines:${exception:format=ToString}}}

一個更好的選擇是列出你所需要的屬性和設置分隔符。所有選項爲${exception} are listed at NLog's wiki。例如:

${exception:format=message,type,method,stacktrace:innerExceptionSeparator=|:separator:,maxInnerExceptionLevel=10}

PS:maxInnerExceptionLevel這裏不需要,但建議設置爲默認值爲0

+0

它不工作我已經嘗試了兩個選項s $ {replace-newlines:$ {exception:format = ToString}} – Salman

+0

$ {exception:format = message,type,method,stacktrace:innerExceptionSeparator = |:separator:,maxInnerExceptionLevel = 10 } – Salman