2016-09-13 118 views
0

我想在我的Xamarin.Droid項目中使用NLog。我安裝了NLog.Config和依賴項,並將NLog.config和NLog.xsd手動移動到Assets文件夾,並將NLog.config生成操作更改爲AndroidAsset。如何在Xamarin Android中使用NLog

正如你可以在Load automatically NLog.config from Assets folder中看到的,我想NLog.config放入Assets文件夾沒有問題。

之後,我改變NLog.config像下面

<targets> 
    <target name="console" xsi:type="Console" layout="${longdate} ${callsite} ${level} ${message}"/> 
</targets> 
<rules> 
    <logger name="*" minlevel="Info" writeTo="console" /> 
</rules> 

之後,我寫了一些代碼,就像下面寫的一些日誌在控制檯

ILogger logger = LogManager.GetCurrentClassLogger(); 
for (int c = 0; c < 1000; ++c) 
    logger.Debug("Hi there"); 

但在那之後我看不到我的任何當「顯示輸出來自」設置爲調試時,Android設備日誌記錄或輸出選項卡中的消息。

我看看正確的地方嗎?

+0

嘗試minlevel'設置''要在Debug'您的配置文件,這會幫助你。 – Anton

+0

另請參閱[Nlog](https://github.com/NLog/NLog/wiki/Configuration-file#log-levels)級別 – Anton

+0

@Anton是的,你是正確的,這是我的錯誤。 –

回答

2

你的配置說定義的MinLevel info

<logger name="*" minlevel="Info" writeTo="console" /> 

,但你正在寫debug水平。低於info

logger.Debug("Hi there"); 

因此改變你的記錄規則:(級別名稱&屬性名稱不區分大小寫)

<logger name="*" minlevel="debug" writeTo="console" /> 
+0

將NLog.config放置到資產是否好方法?或者這是不好的做法? –

+1

我認爲這是,但不確定,因爲它更多Xamarin問題 – Julian