如何解决具有LoggingFacility和core.logging的C#Castle Windsor DI不会记录异常
对于一个项目,我正在使用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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。