Ejemplo n.º 1
0
 private LogDirectory(string path, string prefix, TimeSpan maxAge, LogFileRollOver logFileRollOver, long maxLogFileSize, long maxDirectorySize, string logComponent, bool enforceAccurateAge, string note, int bufferSize, TimeSpan streamFlushInterval) : this(path, prefix, maxAge, logFileRollOver, maxLogFileSize, maxDirectorySize, logComponent, enforceAccurateAge, note, bufferSize, streamFlushInterval, false)
 {
 }
Ejemplo n.º 2
0
        private LogDirectory(string path, string prefix, TimeSpan maxAge, LogFileRollOver logFileRollOver, long maxLogFileSize, long maxDirectorySize, string logComponent, bool enforceAccurateAge, string note, int bufferSize, TimeSpan streamFlushInterval, bool flushToDisk)
        {
            if (streamFlushInterval <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("streamFlushInterval", streamFlushInterval, "streamFlushInterval should be greater than zero");
            }
            if (bufferSize < 0)
            {
                throw new ArgumentOutOfRangeException("bufferSize", bufferSize, "buffer size must be non-negative");
            }
            this.bufferLength       = bufferSize;
            this.directory          = Log.CreateLogDirectory(path);
            this.prefix             = prefix;
            this.maxAge             = maxAge;
            this.logFileRollOver    = logFileRollOver;
            this.maxLogFileSize     = maxLogFileSize;
            this.maxDirectorySize   = maxDirectorySize;
            this.logComponent       = logComponent;
            this.enforceAccurateAge = enforceAccurateAge;
            this.note                = (note ?? string.Empty);
            this.flushToDisk         = flushToDisk;
            this.streamFlushInterval = streamFlushInterval;
            if (maxLogFileSize != 0L)
            {
                this.matcher = new Regex(string.Concat(new string[]
                {
                    "^",
                    Regex.Escape(prefix),
                    enforceAccurateAge ? "(?<year>\\d{4})(?<month>\\d{2})(?<day>\\d{2})(?<hour>\\d{0,2})-(?<instance>\\d+)(?<note>.*)" : "(?<year>\\d{4})(?<month>\\d{2})(?<day>\\d{2})-(?<instance>\\d+)(?<note>.*)",
                    Regex.Escape(".LOG"),
                    "$"
                }), RegexOptions.IgnoreCase);
                this.production  = (enforceAccurateAge ? "{0}{1:yyyyMMddHH}-{2:d}{3}{4}" : "{0}{1:yyyyMMdd}-{2:d}{3}{4}");
                this.dirTemplate = (enforceAccurateAge ? (this.prefix + "????????*-*.LOG") : (this.prefix + "????????-*.LOG"));
                return;
            }
            switch (this.LogFileRollOver)
            {
            case LogFileRollOver.Hourly:
                this.matcher = new Regex(string.Concat(new string[]
                {
                    "^",
                    Regex.Escape(prefix),
                    "(?<year>\\d{4})(?<month>\\d{2})(?<day>\\d{2})(?<hour>\\d{2})-(?<instance>\\d+)(?<note>.*)",
                    Regex.Escape(".LOG"),
                    "$"
                }), RegexOptions.IgnoreCase | RegexOptions.Compiled);
                this.production  = "{0}{1:yyyyMMddHH}-{2:d}{3}{4}";
                this.dirTemplate = this.prefix + "??????????-*.LOG";
                return;

            case LogFileRollOver.Daily:
                this.matcher = new Regex(string.Concat(new string[]
                {
                    "^",
                    Regex.Escape(prefix),
                    "(?<year>\\d{4})(?<month>\\d{2})(?<day>\\d{2})-(?<instance>\\d+)(?<note>.*)",
                    Regex.Escape(".LOG"),
                    "$"
                }), RegexOptions.IgnoreCase | RegexOptions.Compiled);
                this.production  = "{0}{1:yyyyMMdd}-{2:d}{3}{4}";
                this.dirTemplate = this.prefix + "????????-*.LOG";
                return;

            case LogFileRollOver.Weekly:
                this.matcher = new Regex(string.Concat(new string[]
                {
                    "^",
                    Regex.Escape(prefix),
                    "(?<year>\\d{4})(?<month>\\d{2})W(?<week>\\d{1})-(?<instance>\\d+)(?<note>.*)",
                    Regex.Escape(".LOG"),
                    "$"
                }), RegexOptions.IgnoreCase | RegexOptions.Compiled);
                this.production  = "{0}{1:yyyyMM}W{5}-{2:d}{3}{4}";
                this.dirTemplate = this.prefix + "??????W?-*.LOG";
                return;

            case LogFileRollOver.Monthly:
                this.matcher = new Regex(string.Concat(new string[]
                {
                    "^",
                    Regex.Escape(prefix),
                    "(?<year>\\d{4})(?<month>\\d{2})-(?<instance>\\d+)(?<note>.*)",
                    Regex.Escape(".LOG"),
                    "$"
                }), RegexOptions.IgnoreCase | RegexOptions.Compiled);
                this.production  = "{0}{1:yyyyMM}-{2:d}{3}{4}";
                this.dirTemplate = this.prefix + "??????-*.LOG";
                return;

            default:
                throw new InvalidOperationException("The code should never be hit.");
            }
        }
Ejemplo n.º 3
0
 public LogDirectory(string path, string prefix, TimeSpan maxAge, LogFileRollOver logFileRollOver, string logComponent, string note, int bufferSize, TimeSpan streamFlushInterval, bool flushToDisk) : this(path, prefix, maxAge, logFileRollOver, 0L, 0L, logComponent, false, note, bufferSize, streamFlushInterval, flushToDisk)
 {
 }
Ejemplo n.º 4
0
 public LogDirectory(string path, string prefix, LogFileRollOver logFileRollOver, string logComponent, int bufferSize, TimeSpan streamFlushInterval, bool flushToDisk) : this(path, prefix, TimeSpan.MaxValue, logFileRollOver, 0L, 0L, logComponent, false, string.Empty, bufferSize, streamFlushInterval, flushToDisk)
 {
 }
Ejemplo n.º 5
0
 public void Configure(string path, LogFileRollOver logFileRollOver, TimeSpan maxAge)
 {
     this.logImpl.Configure(path, (LogFileRollOver)logFileRollOver, maxAge);
 }
Ejemplo n.º 6
0
 public void Configure(string path, TimeSpan maxAge, long maxDirectorySize, long maxLogFileSize, bool enforceAccurateAge, int bufferSize, TimeSpan streamFlushInterval, LogFileRollOver logFileRollOver)
 {
     this.logImpl.Configure(path, maxAge, maxDirectorySize, maxLogFileSize, enforceAccurateAge, bufferSize, streamFlushInterval, (LogFileRollOver)logFileRollOver);
 }
Ejemplo n.º 7
0
 public void Configure(string path, LogFileRollOver logFileRollOver)
 {
     this.logImpl.Configure(path, (LogFileRollOver)logFileRollOver);
 }
Ejemplo n.º 8
0
 public void Configure(string path, LogFileRollOver logFileRollOver, int bufferSize, TimeSpan streamFlushInterval)
 {
     this.logImpl.Configure(path, (LogFileRollOver)logFileRollOver, bufferSize, streamFlushInterval);
 }
Ejemplo n.º 9
0
        private void Configure(string path, TimeSpan maxAge, LogFileRollOver logFileRollOver, long maxDirectorySize, long maxLogFileSize, bool enforceAccurateAge, int bufferSize, TimeSpan streamFlushInterval, string note, bool flushToDisk)
        {
            if (path == this.path && maxAge == this.maxAge && logFileRollOver == this.logFileRollOver && maxDirectorySize == this.maxDirectorySize && maxLogFileSize == this.maxLogFileSize && enforceAccurateAge == this.enforceAccurateAge && bufferSize == this.bufferSize && streamFlushInterval == this.streamFlushInterval && flushToDisk == this.flushToDisk)
            {
                return;
            }
            Exception ex   = null;
            string    text = null;

            lock (this.logLock)
            {
                this.Close();
                try
                {
                    text = Path.GetFullPath(path);
                    if (maxLogFileSize == 0L)
                    {
                        this.logDirectory = new LogDirectory(text, this.fileNamePrefix, (maxAge == TimeSpan.Zero) ? TimeSpan.MaxValue : maxAge, logFileRollOver, this.logComponent, note, bufferSize, streamFlushInterval, flushToDisk);
                    }
                    else
                    {
                        this.logDirectory = new LogDirectory(text, this.fileNamePrefix, (maxAge == TimeSpan.Zero) ? TimeSpan.MaxValue : maxAge, maxLogFileSize, maxDirectorySize, this.logComponent, enforceAccurateAge, note, bufferSize, streamFlushInterval, flushToDisk);
                    }
                    this.failedToCreateDirectory = false;
                    this.donotAppendCount        = 0;
                    this.donotAppend             = false;
                    this.path                = path;
                    this.maxAge              = maxAge;
                    this.logFileRollOver     = logFileRollOver;
                    this.maxDirectorySize    = maxDirectorySize;
                    this.maxLogFileSize      = maxLogFileSize;
                    this.enforceAccurateAge  = enforceAccurateAge;
                    this.bufferSize          = bufferSize;
                    this.streamFlushInterval = streamFlushInterval;
                    this.flushToDisk         = flushToDisk;
                }
                catch (DirectoryNotFoundException ex2)
                {
                    ex = ex2;
                    this.logDirectory            = null;
                    this.failedToCreateDirectory = true;
                    Log.EventLog.LogEvent(CommonEventLogConstants.Tuple_FailedToCreateDirectory, null, new object[]
                    {
                        this.logComponent,
                        text,
                        ex2.Message
                    });
                }
                catch (ArgumentException ex3)
                {
                    ex = ex3;
                    this.logDirectory            = null;
                    this.failedToCreateDirectory = true;
                    Log.EventLog.LogEvent(CommonEventLogConstants.Tuple_FailedToCreateDirectory, null, new object[]
                    {
                        this.logComponent,
                        text,
                        ex3.Message
                    });
                }
                catch (UnauthorizedAccessException ex4)
                {
                    ex = ex4;
                    this.logDirectory            = null;
                    this.failedToCreateDirectory = true;
                    Log.EventLog.LogEvent(CommonEventLogConstants.Tuple_FailedToCreateDirectory, null, new object[]
                    {
                        this.logComponent,
                        text,
                        ex4.Message
                    });
                }
                catch (IOException ex5)
                {
                    ex = ex5;
                    this.logDirectory            = null;
                    this.failedToCreateDirectory = true;
                    Log.EventLog.LogEvent(CommonEventLogConstants.Tuple_FailedToCreateDirectory, null, new object[]
                    {
                        this.logComponent,
                        text,
                        ex5.Message
                    });
                }
                catch (InvalidOperationException ex6)
                {
                    if (Marshal.GetLastWin32Error() != 122)
                    {
                        throw;
                    }
                    ex = ex6;
                    this.logDirectory            = null;
                    this.failedToCreateDirectory = true;
                    Log.EventLog.LogEvent(CommonEventLogConstants.Tuple_FailedToCreateDirectory, null, new object[]
                    {
                        this.logComponent,
                        text,
                        ex6.Message
                    });
                }
            }
            if (!this.handleKnownExceptions && ex != null)
            {
                throw new LogException("log config failed", ex);
            }
        }
Ejemplo n.º 10
0
 private void Configure(string path, TimeSpan maxAge, LogFileRollOver logFileRollOver, long maxDirectorySize, long maxLogFileSize, bool enforceAccurateAge, int bufferSize, TimeSpan streamFlushInterval, bool flushToDisk)
 {
     this.Configure(path, maxAge, logFileRollOver, maxDirectorySize, maxLogFileSize, enforceAccurateAge, bufferSize, streamFlushInterval, string.Empty, false);
 }
Ejemplo n.º 11
0
 public void Configure(string path, LogFileRollOver logFileRollOver, TimeSpan maxAge)
 {
     this.Configure(path, maxAge, logFileRollOver, 0L, 0L, false, 0, TimeSpan.MaxValue);
 }
Ejemplo n.º 12
0
 public void Configure(string path, LogFileRollOver logFileRollOver, int bufferSize, TimeSpan streamFlushInterval)
 {
     this.Configure(path, TimeSpan.MaxValue, logFileRollOver, 0L, 0L, false, bufferSize, streamFlushInterval);
 }
Ejemplo n.º 13
0
 public void Configure(string path, LogFileRollOver logFileRollOver)
 {
     this.Configure(path, logFileRollOver, 0, TimeSpan.MaxValue);
 }