Dec 30, 2012
7 mins read
IsEnabled() - 確定指定的級別日誌是否啟用
IsTraceEnabled - 確定Trace級別日誌是否啟用
IsDebugEnabled - 確定Debug級別日誌是否啟用
IsInfoEnabled - 確定Info級別日誌是否啟用
IsWarnEnabled - 確定Warn級別日誌是否啟用
IsErrorEnabled - 確定Error級別日誌是否啟用
IsFatalEnabled - 確定Fatal級別日誌是否啟用
LogException() - 使用指定的格式和參數,將訊息和例外寫入指定的級別
TraceException() - 使用指定的格式和參數,將訊息和例外寫入Trace級別
DebugException() - 使用指定的格式和參數,將訊息和例外寫入Debug級別
InfoException() - 使用指定的格式和參數,將訊息和例外寫入Info級別
WarnException() - 使用指定的格式和參數,將訊息和例外寫曾Warn級別
ErrorException() - 使用指定的格式和參數,將訊息和例外寫曾Error級別
FatalException() - 使用指定的格式和參數,將訊息和例外寫曾Fatal級別 ${exception}的詳細設定方式,請參考官網文件
format - 用逗號分隔的例外屬性例表,不區分大小寫 Message, Type, ShortType, ToString, Method, StackTrace
innerFormat - 用逗號分隔的例外屬性例表,不區分大小寫 Message, Type, ShortType, ToString, Method, StackTrace
maxInnerExceptionLevel - 內部錯誤的最大層數 ${onexception} - 用來輸出內部例外 範例 StackTrace:${exception:format=stacktrace} Exception Type:${exception:format=type} Exception Message:${exception:format=message} Inner Exception :${onexception:${exception:format=type,message,method:maxInnerExceptionLevel=5:innerFormat=shortType,message,method}}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using NLog;namespace NLogApp { class Program { static readonly Logger log = LogManager.GetLogger(“Program”);
static void Main(string[] args) { log.Debug("Debug Message..."); } }
}
using System; using System.Globalization; using NLog;class MyClass { static Logger logger = LogManager.GetLogger(“MyClass”);
public void LogSomething() { LogEventInfo myEvent = new LogEventInfo(LogLevel.Debug, "", "My debug message"); myEvent.LoggerName = logger.Name; myEvent.Properties.Add("MyCustomValue", "This is from MyClass"); logger.Log(myEvent); }
}
Sharing is caring!