问题描述
对于一个项目,我正在使用Castle Windsor DI(对我来说是新的)。具有接口Castle.Core.Logging
的{{1}}名称空间具有以下方法(还具有Debug,Error等):
-
Logger
-
void Fatal(string message,Exception exception);
但是,当我使用带有exception参数的方法时,它仅记录消息,而不记录异常。我似乎无法弄清楚为什么它只记录消息,也许我错过了设置?当前NLog用于记录日志。记录器被注入到这样的基类中:
void Fatal(string message);
此设置来自NLog and Castle Logging Facility for Logging
解决方法
您可以在Nlog配置文件中进行设置,从而自定义布局和Nlog将为您提供的消息内容。 为此,您可以编写例如:
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="logfile" fileName="c:\temp\console-example.log"
layout="${longdate}|${level}|${message} |${all-event-properties}${exception:format=tostring}" />
<target xsi:type="Console" name="logconsole"
layout="${longdate}|${level}|${message} |${all-event-properties}${exception:format=tostring}" />
</targets>
https://github.com/NLog/NLog/wiki/Getting-started-with-.NET-Core-2---Console-application