【问题标题】:Why aren't nLog custom event properties rendering through an email target?为什么不通过电子邮件目标呈现 nLog 自定义事件属性?
【发布时间】:2015-12-07 15:12:30
【问题描述】:

我有一个门面用于结束我的 nLog 调用。我正在使用 nLog 的事件属性来添加自定义“longMessage”字段。代码如下:

public void Fatal(string shortMessage, string longMessage, Exception exception = null)
{
    Logger _logger = LogManager.GetCurrentClassLogger();
    LogEventInfo theEvent = new LogEventInfo(LogLevel.Debug, "", "Pass my custom value");
    theEvent.Message = shortMessage;
    theEvent.Properties["LongMessage"] = longMessage;
    theEvent.Exception = exception;
    _logger.Fatal(theEvent);
}

当我将 nLog 事件写入文件或数据库目标时,LongMessage 字段会正确呈现。但是当我写信给电子邮件时,我的长消息应该是一个空字符串。任何想法为什么输出属性可以在数据库目标中工作但在电子邮件目标中不起作用?

<target name="themail" xsi:type="Mail"
    smtpServer="VALID.INTERNAL.IP"
    from="sender@address.com"
    to="recip@address.com"
    subject="${event-properties:item=LongMessage}"
    body="${all-event-properties:format=[key]=[value]:separator=,:includeCallerInformation=true}"
    html="true"
    encoding="UTF-8">

我收到电子邮件就好了。它很好。但主题和正文只是空白。我已经在主题和正文中添加了其他内容,以确保我在电子邮件的主题和正文中得到了一些东西,这也很有效。除了 event-properties 查找之外,一切都可以正常工作 - 并且仅在电子邮件目标上不起作用。

【问题讨论】:

标签: nlog


【解决方案1】:

我认为您需要转义格式中的等号 - 这就是我最终想出的:

${all-event-properties:format=[key]\=[value]:separator=,:includeCallerInformation=true}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多