Esempio n. 1
0
        private Periodicity DeterminePeriodicityType()
        {
            var periodicRollingCalendar = new PeriodicRollingCalendar(this.format, this.period);
            var epoch = new DateTime(1970, 1, 1);

            foreach (var i in ValidOrderedList)
            {
                string r0 = epoch.ToString(this.format);
                periodicRollingCalendar.PeriodicityType = i;

                var    next = periodicRollingCalendar.NextTriggeringTime(epoch, 1);
                string r1   = next.ToString(this.format);

                if (r0 != r1)
                {
                    return(i);
                }
            }

            return(Periodicity.ERRONEOUS);
        }
Esempio n. 2
0
        /// <summary>
        /// Works like the CopyStream method but does a log rotation based on time.
        /// </summary>
        private void CopyStreamWithDateRotation(StreamReader reader, string ext)
        {
            var periodicRollingCalendar = new PeriodicRollingCalendar(this.Pattern, this.Period);

            periodicRollingCalendar.Init();

            var writer = new FileStream(this.BaseLogFileName + "_" + periodicRollingCalendar.Format + ext, FileMode.Append);
            var copy   = new StreamCopyOperation(reader.BaseStream, writer);

            while (copy.CopyLine() != 0)
            {
                if (periodicRollingCalendar.ShouldRoll)
                {
                    writer.Dispose();
                    copy.Writer = writer = new FileStream(this.BaseLogFileName + "_" + periodicRollingCalendar.Format + ext, FileMode.Create);
                }
            }

            reader.Dispose();
            writer.Dispose();
        }
Esempio n. 3
0
        /// <summary>
        /// Works like the CopyStream method but does a log rotation based on time.
        /// </summary>
        private void CopyStreamWithDateRotation(StreamReader reader, string ext)
        {
            PeriodicRollingCalendar periodicRollingCalendar = new PeriodicRollingCalendar(this.Pattern, this.Period);

            periodicRollingCalendar.Init();

            StreamWriter writer = this.CreateWriter(new FileStream(this.BaseLogFileName + "_" + periodicRollingCalendar.Format + ext, FileMode.Append));
            string?      line;

            while ((line = reader.ReadLine()) != null)
            {
                if (periodicRollingCalendar.ShouldRoll)
                {
                    writer.Dispose();
                    writer = this.CreateWriter(new FileStream(this.BaseLogFileName + "_" + periodicRollingCalendar.Format + ext, FileMode.Create));
                }

                writer.WriteLine(line);
            }

            reader.Dispose();
            writer.Dispose();
        }