2015-08-20 39 views
0

我正在嘗試在本地域上部署的C#應用​​程序中使用NLog。Nlog通過交換機發送

每個用戶都有一個交換郵箱,直到現在,我一直在使用Office.Interop和一個基本的日誌記錄類從內置交換賬戶發送結果。

有沒有什麼辦法可以和NLog做類似的事情,我不能在他們的文檔中看到任何可以讓我這樣做的東西。

回答

1

您可以使用NLOG Mail Target結合,用(A)的Windows Identity Layout Renderer(如果你可以構建從用戶名登錄的mailaddress)

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

或(b)的EventProperties Layout Renderer(原EventContext)至從你的應用程序提供mailaddress。

/* 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}" 
    ...>