Пример #1
0
 protected override void Initialize()
 {
     Buffer = new MessageFileLoggerListenerStateInfo
     {
         Buffer                = new List <TraceMessage>(),
         Locker                = new object(),
         ResetEvent            = new AutoResetEvent(false),
         RollingFile           = Convert.ToInt32(DateTime.Now.TimeOfDay.TotalSeconds).ToString(CultureInfo.InvariantCulture),
         LastFileRetentionDate = DateTime.Today.AddDays(-1)
     };
 }
Пример #2
0
        protected override void Initialize()
        {
            _retentionDays   = GetRetentionDays();
            _maxFileSize     = GetMaxFileSize();
            _directory       = GetLogDirectory();
            _applicationName = GetApplicationName();

            Buffer = new MessageFileLoggerListenerStateInfo
            {
                Buffer                = new List <TraceMessage>(),
                Locker                = new object(),
                ResetEvent            = new AutoResetEvent(false),
                RollingFile           = Convert.ToInt32(DateTime.Now.TimeOfDay.TotalSeconds).ToString(CultureInfo.InvariantCulture),
                LastFileRetentionDate = DateTime.Today.AddDays(-1)
            };
        }
Пример #3
0
        protected string GetFileName(MessageFileLoggerListenerStateInfo bufferStateInfo)
        {
            var rollingFile = bufferStateInfo.RollingFile;

            // Check if I need to roll the file because we reached the limit.
            var fileName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}_{2}_{3}_{4}.log", _applicationName,
                                         DateTime.Today.Year.ToString("0000"),
                                         DateTime.Today.Month.ToString("00"),
                                         DateTime.Today.Day.ToString("00"),
                                         rollingFile);

            if (File.Exists(System.IO.Path.Combine(_directory, fileName)))
            {
                var fi = new FileInfo(System.IO.Path.Combine(_directory, fileName));
                if (fi.Length > _maxFileSize)
                {
                    rollingFile = Convert.ToInt32(DateTime.Now.TimeOfDay.TotalSeconds).ToString();
                    bufferStateInfo.RollingFile = rollingFile;

                    fileName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}_{2}_{3}_{4}.log",
                                             _applicationName,
                                             DateTime.Today.Year.ToString("0000"),
                                             DateTime.Today.Month.ToString("00"),
                                             DateTime.Today.Day.ToString("00"),
                                             rollingFile);
                }
            }

            if (bufferStateInfo.LastFileRetentionDate < DateTime.Today)
            {
                try
                {
                    CleanLogFiles();

                    bufferStateInfo.LastFileRetentionDate = DateTime.Today;
                }
                catch (Exception ex)
                {
                    LogMessage(ex.ToString());
                }
            }

            return(System.IO.Path.Combine(_directory, fileName));
        }