public Log(string fileNamePrefix, LogHeaderFormatter headerFormatter, string logComponent, bool handleKnownExceptions) { this.headerFormatter = headerFormatter; this.fileNamePrefix = fileNamePrefix; this.logComponent = logComponent; this.handleKnownExceptions = handleKnownExceptions; this.maxWaitAppendCount = 50; }
public Stream GetLogFile(DateTime forDate, LogHeaderFormatter logHeaderFormatter, bool forceLogFileRollOver) { if (this.logFile != null) { try { if (forceLogFileRollOver || !this.logFileId.SameLogSeries(forDate, this) || (this.maxLogFileSize > 0L && this.logFile.Position > this.maxLogFileSize)) { this.logFile.Close(); this.logFile = null; } } catch (ObjectDisposedException) { this.logFile = null; } } if (this.logFile == null) { lock (this.fileRollOverLock) { if (this.logFile == null) { SortedList <LogDirectory.LogFileId, FileInfo> logFileList = this.GetLogFileList(); int num = this.EnforceDirectorySizeQuota(logFileList); if (num > 0) { Log.EventLog.LogEvent(CommonEventLogConstants.Tuple_DeleteLogDueToQuota, null, new object[] { this.logComponent, this.FullName, this.maxDirectorySize, num }); LogDirectory.OnDirSizeQuotaExceededHandler onDirSizeQuotaExceeded = this.OnDirSizeQuotaExceeded; if (onDirSizeQuotaExceeded != null) { onDirSizeQuotaExceeded(this.logComponent, this.FullName, this.maxDirectorySize, num); } } if (this.maxAge < TimeSpan.MaxValue) { this.DeleteOldLogFiles(logFileList, num, forDate - this.maxAge); } bool startNewLog = forceLogFileRollOver || (logHeaderFormatter != null && logHeaderFormatter.CsvOption == LogHeaderCsvOption.CsvStrict); bool flag2 = false; this.logFileId = this.GenerateLogFileId(logFileList, forDate, startNewLog, out flag2); int i = 0; while (i < 20) { try { this.logFile = new LogDirectory.BufferedStream(this.GetLogFileNameFromId(this.logFileId), this.bufferLength, this.flushToDisk); if (this.maxLogFileSize > 0L && this.logFile.Position > this.maxLogFileSize) { this.logFile.Close(); this.logFile = null; } } catch (IOException) { this.logFile = null; } if (this.logFile == null) { this.logFileId = this.logFileId.Next; flag2 = true; i++; } else { if (logHeaderFormatter != null && flag2) { logHeaderFormatter.Write(this.logFile, forDate); } if (this.streamFlushTimer == null && this.streamFlushInterval != TimeSpan.MaxValue) { this.streamFlushTimer = new Timer(new TimerCallback(this.FlushStream), null, TimeSpan.Zero, this.streamFlushInterval); break; } break; } } } } } return(this.logFile); }
public Log(string fileNamePrefix, LogHeaderFormatter headerFormatter, string logComponent) : this(fileNamePrefix, headerFormatter, logComponent, true) { }