2012-05-05 49 views
0

是否可以通過代碼更改source名稱?我的解決方案有幾個模塊,我想在查看日誌時將它們分開。NLog:是否可以從代碼更改源名稱?

<?xml version="1.0" encoding="utf-8" ?> 
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <targets> 
    <target xsi:type="EventLog" name="eventlog" layout="${message}" log="Application" source="MyAwesomeSolution"/> 
    </targets> 
    <rules> 
    <logger name="*" minlevel="Info" writeTo="eventLog" /> 
    </rules> 
</nlog> 

另外,如何將對象記錄爲xml?例如如果我這樣做 - logger.Info("Results - {0}", person);我想在我的事件日誌中將person對象視爲XML。可能嗎?

回答

0

Initalize與

private static Logger logger = LogManager.GetCurrentClassLogger(); 

那麼你的Logger對象,你可以在配置文件中

例如添加

${callsite}到您的佈局

<targets> 
    <target xsi:type="EventLog" name="eventlog" layout="${callsite}:${message}" log="Application" source="MyAwesomeSolution"/> 
</targets> 

更多信息@ $ {callsite}是here

+0

謝謝。我會試一試。 – tempid

相關問題