Nlog 通过交换发送

Nlog send by exchange

我正在尝试在部署在本地域上的 C# 应用程序中使用 NLog。

每个用户都有一个交换邮箱,到目前为止,我一直在使用 Office.Interop 和基本日志记录 class 从他们的内置交换帐户发送结果。

有没有什么方法可以用 NLog 做类似的事情,我在他们的文档中看不到任何允许我这样做的东西。

您可以使用 NLog Mail Target in combination, with (a) the Windows Identity Layout Renderer(如果您可以从登录的用户名构造邮件地址)

<!-- In your NLog.config. -->
<target
    ...
    from="${windows-identity:domain=false}@yourcompany.com"
    ...>

或 (b) EventProperties Layout Renderer(以前称为 EventContext)从您的应用程序中提供邮件地址。

/* In your code. */
LogEventInfo theEvent = new LogEventInfo(LogLevel.Debug, "", "Pass my custom value");

theEvent.Properties["MailAddress"] = theUsersMailAddress;
myLogger.Log(theEvent);
<!-- In your NLog.config. -->
<target
    ...    
    from="${event-properties:item=MailAddress}"
    ...>