帮助我请格式化与文件记录器记录的异常 我想异常类型包围内部异常(如果有的话)之间的新行分隔符记录使用一些特殊类型的符号,如[ArgumentException]
使其与错误文本不同,并且要使用选项卡以便易于读取堆栈跟踪的例外nlog异常布局来格式化异常类型,消息和堆栈跟踪
我已经检查了最新的NLog 4.4.12软件包,但问题在于将参数化默认布局并非如此简单以获得像
2017-10-04 15:13:22.5823 NLogTest.Program starting
2017-10-04 15:13:22.5823 NLogTest.Program failed to start NLogTest
[ArgumentException] bad try
at NLogTest.Classes.UnitOfWork.tryException() in d:\projects\NLogTest\Program.cs:line 62
at NLogTest.Program.Main(String[] args) in d:\projects\NLogTest\Program.cs:line 19
[ArgumentException] outer exception
at NLogTest.Classes.UnitOfWork.outerException() in d:\projects\NLogTest\Program.cs:line 49
at NLogTest.Classes.UnitOfWork.tryException() in d:\projects\NLogTest\Program.cs:line 57
[KeyNotFoundException] innerException
at NLogTest.Classes.UnitOfWork.innerException() in d:\projects\NLogTest\Program.cs:line 38
at NLogTest.Classes.UnitOfWork.outerException() in d:\projects\NLogTest\Program.cs:line 45
2017-10-04 15:13:22.5823 NLogTest.Program the end
这是我希望得到的异常文件日志。 我已经与布局试图像
layout="${longdate} ${logger} ${message}${onexception:${newline}${exception:format=tostring}}"
它使用标准的toString方法例外,但结果是不一样的。我不喜欢这样
2017-10-04 15:28:52.6881 NLogTest.Program failed to start NLogTest
System.ArgumentException: bad try ---> System.ArgumentException: outer exception ---> System.Collections.Generic.KeyNotFoundException: innerException
at NLogTest.Classes.UnitOfWork.innerException() in d:\projects\NLogTest\Program.cs:line 40
at NLogTest.Classes.UnitOfWork.outerException() in d:\projects\NLogTest\Program.cs:line 47
--- End of inner exception stack trace ---
at NLogTest.Classes.UnitOfWork.outerException() in d:\projects\NLogTest\Program.cs:line 51
at NLogTest.Classes.UnitOfWork.tryException() in d:\projects\NLogTest\Program.cs:line 59
--- End of inner exception stack trace ---
at NLogTest.Classes.UnitOfWork.tryException() in d:\projects\NLogTest\Program.cs:line 64
at NLogTest.Program.Main(String[] args) in d:\projects\NLogTest\Program.cs:line 20
内部异常的消息堆栈跟踪日志中的(所以它是很难读以后登录)的情况下,如果异常被再次抛出更多的则两次 并没有标签(被分离空格)在异常类型名称之前。
最好的结果,我得到的是与布局低于
layout="${longdate} ${logger} ${message}${onexception:${newline}${exception:maxInnerExceptionLevel=10:format=shortType,message,stacktrace:separator=*:innerExceptionSeparator=
	}}"
,这是
2017-10-04 15:49:02.6188 NLogTest.Program failed to start NLogTest
ArgumentException*bad try* at NLogTest.Classes.UnitOfWork.tryException() in d:\projects\NLogTest\Program.cs:line 64
at NLogTest.Program.Main(String[] args) in d:\projects\NLogTest\Program.cs:line 20
ArgumentException*outer exception* at NLogTest.Classes.UnitOfWork.outerException() in d:\projects\NLogTest\Program.cs:line 51
at NLogTest.Classes.UnitOfWork.tryException() in d:\projects\NLogTest\Program.cs:line 59
KeyNotFoundException*innerException* at NLogTest.Classes.UnitOfWork.innerException() in d:\projects\NLogTest\Program.cs:line 40
at NLogTest.Classes.UnitOfWork.outerException() in d:\projects\NLogTest\Program.cs:line 47
但是这是很难看的。第一个堆栈跟踪线与异常消息位于同一行。内部错误消息的目的是内部堆栈跟踪 - 没有。
有什么布局,我错过了? 我应该create custom exception layout renderer? Here is我用来提升异常的c#源代码