/// <summary> /// 写日志以前的准备工作 /// </summary> override public void ActivateAppender() { if (m_lockingModel == null) { switch (LogConfig.Instance.LockType) { //独占锁 case LockingType.Exclusive: m_lockingModel = new ExclusiveLock(); break; //跨进程文件锁定 case LockingType.InterProcess: m_lockingModel = new InterProcessLock(); break; //最小时间锁 case LockingType.Minimal: m_lockingModel = new MinimalLock(); break; } } m_lockingModel.CurrentAppender = this; if (m_fileName != null) { PrepareWriter(); } }
/// <summary> /// ログを出力先を指定して、<c>FileHeavyLogger</c>クラスの新規インスタンスを初期化します。 /// </summary> /// <param name="path">ログの出力先ファイルパス</param> /// <param name="name">ログ名</param> public FileHeavyLogger(string path, string name) { this._path = path; this.ConfigureLogger(); this._logger = LogManager.GetLogger(name); this._lock = null; }
/// <summary> /// ログを出力先を指定して、<c>FileHeavyLogger</c>クラスの新規インスタンスを初期化します。 /// </summary> /// <param name="path">ログの出力先ファイルパス</param> /// <param name="name">ログ名</param> /// <param name="lock_">ログの排他制御に使用するロック</param> public FileHeavyLogger(string path, string name, InterProcessLock lock_) { this._path = path; this.ConfigureLogger(); this._logger = LogManager.GetLogger(name); this._lock = lock_; }
/// <summary> /// 打开文件为写日志操作做准备 /// </summary> /// <param name="fileName">文件名</param> /// <param name="append">是否添加日志信息到文件尾</param> virtual protected void OpenFile(string fileName, bool append) { lock (this) { //先进行关闭之前打开的文件 Reset(); // 保存这些后, 允许重试如果打开文件失败 m_fileName = fileName; m_appendToFile = append; switch (LogConfig.Instance.LockType) { //独占 case LockingType.Exclusive: m_lockingModel = new ExclusiveLock(); break; //跨进程文件锁 case LockingType.InterProcess: m_lockingModel = new InterProcessLock(); break; //最小时间 case LockingType.Minimal: m_lockingModel = new MinimalLock(); break; } // LockingModel.CurrentAppender = this; //打开文件 LockingModel.OpenFile(fileName, append, m_encoding); m_stream = new LockingStream(LockingModel); if (m_stream != null) { m_stream.AcquireLock(); try { SetQWForFiles(new StreamWriter(m_stream, m_encoding)); } finally { m_stream.ReleaseLock(); } } } }