/// <summary> /// 初始化 /// </summary> private void Init() { this._fileLogWriter = null; var fileAppenderConfig = (FileAppenderConfig)base._config; this._fileAppenderConfig = fileAppenderConfig; var pathManager = new FileAppenderPathManager(this._fileAppenderConfig); switch (this._fileAppenderConfig.LockingModel) { case LockingModel.Exclusive: this._fileLogWriter = new ExclusiveFileLogWriter(fileAppenderConfig, pathManager); break; case LockingModel.Minimal: this._fileLogWriter = new MinimalFileLogWriter(fileAppenderConfig, pathManager); break; case LockingModel.InterProcess: this._fileLogWriter = new InterProcessFileLogWriter(fileAppenderConfig, pathManager); break; default: LogSysInnerLog.OnRaiseLog(this, new NotSupportedException(string.Format("不支持的锁模型:{0}", this._fileAppenderConfig.LockingModel.ToString()))); break; } }
/// <summary> /// 写日志 /// </summary> /// <param name="fileAppenderConfig">配置</param> /// <param name="pathManager">路由管理器</param> /// <param name="createFilePathTime">创建时间</param> /// <param name="logMessage">日志信息项</param> protected override void WriteLog(FileAppenderConfig fileAppenderConfig, FileAppenderPathManager pathManager, DateTime createFilePathTime, LogMessageItem logMessage) { DateTime currentTime = DateTime.Now; if (this._sw != null && !pathManager.IsFixPath && (fileAppenderConfig.MaxFileLength > 0 && this._sw.BaseStream.Length >= fileAppenderConfig.MaxFileLength || currentTime.Year != createFilePathTime.Year || currentTime.Month != createFilePathTime.Month || currentTime.Day != createFilePathTime.Day)) { this._sw.Close(); this._sw = null; } if (this._sw == null) { string logFilePath = base.GetLogFilePath(); if (string.IsNullOrWhiteSpace(logFilePath)) { return; } this._sw = File.AppendText(logFilePath); } base.WriteLogToFile(logMessage, this._sw); }
/// <summary> /// 写日志 /// </summary> /// <param name="fileAppenderConfig">配置</param> /// <param name="pathManager">路由管理器</param> /// <param name="createFilePathTime">创建时间</param> /// <param name="logMessage">日志信息项</param> protected override void WriteLog(FileAppenderConfig fileAppenderConfig, FileAppenderPathManager pathManager, DateTime createFilePathTime, LogMessageItem logMessage) { string logFilePath = base.GetLogFilePath(); if (string.IsNullOrWhiteSpace(logFilePath)) { return; } using (var sw = File.AppendText(logFilePath)) { base.WriteLogToFile(logMessage, sw); } }
public FileLogWriterBase(FileAppenderConfig fileAppenderConfig, FileAppenderPathManager pathManager) { this._fileAppenderConfig = fileAppenderConfig; this._pathManager = pathManager; try { Type type = LogUtil.GetType(fileAppenderConfig.SecurityPolicy); if (type != null && type.GetInterface(typeof(ILogSecurityPolicy).FullName) != null) { this._securityPolicy = Activator.CreateInstance(type) as ILogSecurityPolicy; } } catch (Exception ex) { LogSysInnerLog.OnRaiseLog(this, ex); } }
/// <summary> /// 写日志 /// </summary> /// <param name="fileAppenderConfig">配置</param> /// <param name="pathManager">路由管理器</param> /// <param name="createFilePathTime">创建时间</param> /// <param name="logMessage">日志信息项</param> protected override void WriteLog(FileAppenderConfig fileAppenderConfig, FileAppenderPathManager pathManager, DateTime createFilePathTime, LogMessageItem logMessage) { Mutex mutex = null; try { string logFilePath = base.GetLogFilePath(); if (string.IsNullOrWhiteSpace(logFilePath)) { return; } mutex = this.GetMutex(logFilePath); using (var sw = File.AppendText(logFilePath)) { //日志处理 base.WriteLogToFile(logMessage, sw); } } finally { this.ReleaseMutex(mutex); } }
public ExclusiveFileLogWriter(FileAppenderConfig fileAppenderConfig, FileAppenderPathManager pathManager) : base(fileAppenderConfig, pathManager) { }
public MinimalFileLogWriter(FileAppenderConfig fileAppenderConfig, FileAppenderPathManager pathManager) : base(fileAppenderConfig, pathManager) { }
public InterProcessFileLogWriter(FileAppenderConfig fileAppenderConfig, FileAppenderPathManager pathManager) : base(fileAppenderConfig, pathManager) { }
/// <summary> /// 写日志 /// </summary> /// <param name="fileAppenderConfig">配置</param> /// <param name="pathManager">路由管理器</param> /// <param name="createFilePathTime">创建时间</param> /// <param name="logMessage">日志信息项</param> protected abstract void WriteLog(FileAppenderConfig fileAppenderConfig, FileAppenderPathManager pathManager, DateTime createFilePathTime, LogMessageItem logMessage);