You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
using NLog; using NLog.Config; using NLog.Targets;
namespace Mirle.Component.Record { /// <summary>
/// 記錄檔類別
/// </summary>
public class LogWrapper { /// <summary>
/// 建構式
/// </summary>
private LogWrapper() { } /// <summary>
/// 關聯式資料庫物件
/// </summary>
private static volatile LogWrapper _logFile; /// <summary>
/// 物件鎖定
/// </summary>
private static readonly object _syncRoot = new object(); /// <summary>
/// 記錄設定檔
/// </summary>
private static readonly LoggingConfiguration _loggingConfiguration = new LoggingConfiguration(); /// <summary>
/// 紀錄檔實例
/// </summary>
public static LogWrapper Instance { get { if (_logFile == null) { lock (_syncRoot) // 鎖定避免多執行緒重覆呼叫建立物件
{ _logFile = new LogWrapper(); } } return _logFile; } } /// <summary>
/// 取得記錄器
/// </summary>
/// <param name="logger">紀錄器名稱</param>
/// <param name="fileTarget">紀錄器設定檔</param>
/// <returns>紀錄器物件</returns>
public Logger GetLogger(string logger, FileTarget fileTarget) { _loggingConfiguration.AddRuleForAllLevels(fileTarget, logger); LogManager.Configuration = _loggingConfiguration; return LogManager.GetLogger(logger); } } }
|