Beispiel #1
0
            public bool SameLogSeries(DateTime date, LogDirectory logDirectory)
            {
                if (!this.note.Equals(logDirectory.Note, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
                if (logDirectory.MaxLogFileSize != 0L)
                {
                    return(logDirectory.MaxLogFileSize == long.MaxValue || ((!logDirectory.EnforceAccurateAge || this.Date.Hour == date.Hour) && (this.Date.Year == date.Year && this.Date.Month == date.Month) && this.Date.Day == date.Day));
                }
                switch (logDirectory.LogFileRollOver)
                {
                case LogFileRollOver.Hourly:
                    return(this.Date.Year == date.Year && this.Date.Month == date.Month && this.Date.Day == date.Day && this.Date.Hour == date.Hour);

                case LogFileRollOver.Daily:
                    return(this.Date.Year == date.Year && this.Date.Month == date.Month && this.Date.Day == date.Day);

                case LogFileRollOver.Weekly:
                    return(this.Date.Year == date.Year && this.Date.Month == date.Month && LogDirectory.GetWeekNumber(this.Date) == LogDirectory.GetWeekNumber(date));

                case LogFileRollOver.Monthly:
                    return(this.Date.Year == date.Year && this.Date.Month == date.Month);

                default:
                    throw new InvalidOperationException("The code should never be hit.");
                }
            }
Beispiel #2
0
        private string GetLogFileNameFromId(LogDirectory.LogFileId id)
        {
            int weekNumber = LogDirectory.GetWeekNumber(id.Date);

            return(Path.Combine(this.FullName, string.Format(CultureInfo.InvariantCulture, this.production, new object[]
            {
                this.prefix,
                id.Date,
                id.Instance,
                this.note,
                ".LOG",
                weekNumber
            })));
        }
Beispiel #3
0
        private void FlushStream(object state)
        {
            Stream stream = this.logFile;

            if (stream != null)
            {
                try
                {
                    stream.Flush();
                }
                catch (IOException ex)
                {
                    if (!LogDirectory.IsDiskFullException(ex))
                    {
                        Log.EventLog.LogEvent(CommonEventLogConstants.Tuple_FailedToAppendLog, null, new object[]
                        {
                            this.logComponent,
                            ex.Message
                        });
                    }
                }
            }
        }
Beispiel #4
0
        private LogDirectory.LogFileId GetLogFileIdFromName(string filename)
        {
            Match match = this.matcher.Match(filename);

            if (!match.Success)
            {
                return(null);
            }
            int      hour = 0;
            int      instance;
            DateTime date;
            string   value2;

            try
            {
                int year  = Convert.ToInt32(match.Groups["year"].Captures[0].Value, CultureInfo.InvariantCulture);
                int month = Convert.ToInt32(match.Groups["month"].Captures[0].Value, CultureInfo.InvariantCulture);
                instance = Convert.ToInt32(match.Groups["instance"].Captures[0].Value, CultureInfo.InvariantCulture);
                if (this.maxLogFileSize == 0L)
                {
                    switch (this.LogFileRollOver)
                    {
                    case LogFileRollOver.Hourly:
                    {
                        int day = Convert.ToInt32(match.Groups["day"].Captures[0].Value, CultureInfo.InvariantCulture);
                        hour = Convert.ToInt32(match.Groups["hour"].Captures[0].Value, CultureInfo.InvariantCulture);
                        date = new DateTime(year, month, day, hour, 0, 0);
                        break;
                    }

                    case LogFileRollOver.Daily:
                    {
                        int day = Convert.ToInt32(match.Groups["day"].Captures[0].Value, CultureInfo.InvariantCulture);
                        date = new DateTime(year, month, day);
                        break;
                    }

                    case LogFileRollOver.Weekly:
                    {
                        int week = Convert.ToInt32(match.Groups["week"].Captures[0].Value, CultureInfo.InvariantCulture);
                        date = LogDirectory.GetFirstDateForWeek(year, month, week);
                        break;
                    }

                    case LogFileRollOver.Monthly:
                        date = new DateTime(year, month, 1);
                        break;

                    default:
                        throw new InvalidOperationException("The code should never be hit.");
                    }
                }
                else
                {
                    int day = Convert.ToInt32(match.Groups["day"].Captures[0].Value, CultureInfo.InvariantCulture);
                    if (this.enforceAccurateAge)
                    {
                        string value = match.Groups["hour"].Captures[0].Value;
                        if (!string.IsNullOrEmpty(value))
                        {
                            hour = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                        }
                    }
                    date = (this.enforceAccurateAge ? new DateTime(year, month, day, hour, 0, 0) : new DateTime(year, month, day));
                }
                value2 = match.Groups["note"].Captures[0].Value;
            }
            catch (ArgumentOutOfRangeException)
            {
                return(null);
            }
            catch (FormatException)
            {
                return(null);
            }
            catch (OverflowException)
            {
                return(null);
            }
            return(new LogDirectory.LogFileId(date, value2, instance));
        }