2017-02-13 156 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