简体   繁体   English

带有 LoggingFacility 和 core.logging 的 C# Castle Windsor DI 不记录异常

[英]C# Castle Windsor DI with LoggingFacility and core.logging doesn't log Exception

For a project I'm using Castle Windsor DI (new for me).对于一个项目,我正在使用 Castle Windsor DI(对我来说是新的)。 The Castle.Core.Logging namespace with its interface Logger has these methods (also with Debug, Error etc): Castle.Core.Logging命名空间及其接口Logger具有以下方法(还有 Debug、Error 等):

  • void Fatal(string message, Exception exception);
  • void Fatal(string message);

However, when I'm using the methods with the exception parameter, it only logs the message, not the exception.但是,当我使用带有异常参数的方法时,它只记录消息,而不记录异常。 I can't seem to figure out why it only logs the message, maybe I missed a setting?我似乎无法弄清楚为什么它只记录消息,也许我错过了一个设置? Currently NLog is used for logging.目前 NLog 用于日志记录。 The logger is injected in a base class like this:记录器被注入到一个基类中,如下所示:

public ILogger Log { get; set; } = NullLogger.Instance;

This setup is from NLog and Castle Logging Facility for Logging此设置来自NLog 和 Castle Logging Facility for Logging

You can customize the layout and the content of the messages Nlog will give you by setting this inside the Nlog config file.您可以通过在 Nlog 配置文件中进行设置来自定义 Nlog 将给您的消息的布局和内容。 For this you could write for example:为此,您可以编写例如:

<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 https://github.com/NLog/NLog/wiki/Getting-started-with-.NET-Core-2---Console-application

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM