2017年8月2日 星期三

[C#]NuGet - NLog using Log2Console


  • Log2Console 即時檢視 NLog
    • 首先需先設定 Receivers
    • 這次範例選擇 TCP 進行測試,如:程式正在執行中,可利用此方法進行監控
    • 創建時提供 NLog.config 的 Sample code
    • NLog.config Code
    < variable name="DemoLayout" value="${longdate} ${uppercase:${level}} ${message}"/>
    < targets>
      < target
        name="TcpOutlet"
        xsi:type="NLogViewer"
        address="tcp://localhost:4505"
        layout="${DemoLayout}" />
      < target
        name="f"
        xsi:type="File"
        fileName="${basedir}/logs/${shortdate}.log"
        layout="${DemoLayout}" />
    < /targets>
    < rules>
      < logger name="*" minlevel="Debug" writeTo="TcpOutlet" />
      < logger name="*" minlevel="Debug" writeTo="f" />
    < /rules>
    C#
    • Function Code
    Logger logger = LogManager.GetLogger("DemoFileLog");
    logger.Info("Info Lyndon");
    logger.Error("Error Demo");
    C#
    • Result
  • Ref
    • https://dotblogs.com.tw/wasichris/2015/02/27/150582

沒有留言:

張貼留言