Exemplo n.º 1
0
        /// <summary>
        /// 写日志到文件
        /// </summary>
        /// <param name="logMessage">日志信息项</param>
        /// <param name="sw">StreamWriter</param>
        protected void WriteLogToFile(LogMessageItem logMessage, StreamWriter sw)
        {
            string logMsg = logMessage.LogMsg;

            if (this._securityPolicy != null)
            {
                logMsg = this._securityPolicy.Encryption(logMsg);
            }

            sw.WriteLine(logMsg);
            sw.Flush();
            this._fileSize = sw.BaseStream.Length;
        }
Exemplo n.º 2
0
        /// <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);
            }
        }
        /// <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);
            }
        }
Exemplo n.º 5
0
 /// <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);
Exemplo n.º 6
0
 /// <summary>
 /// 写日志
 /// </summary>
 /// <param name="logMessage">日志信息项</param>
 public void WriteLog(LogMessageItem logMessage)
 {
     this.WriteLog(this._fileAppenderConfig, this._pathManager, this._createFilePathTime, logMessage);
 }