コード例 #1
0
        public void WhenGettingFilePath_ReturnCorrectName(RollingFilePeriod period, int minutesToAdd, string expected)
        {
            CreateDummyFiles(period);
            var namer = new RollingFileNamer(tempFolder.FolderPath, period);

            var fileName = Path.GetFileName(namer.GetFilePath(BaseDate.AddMinutes(minutesToAdd)));

            Assert.Equal(expected, fileName);
        }
コード例 #2
0
        public void WhenCheckingForUpdate_ReturnBool(RollingFilePeriod period, int minutesToAdd, bool expected)
        {
            CreateDummyFiles(period);
            var namer = new RollingFileNamer(tempFolder.FolderPath, period);

            var shouldUpdate = namer.ShouldUpdateFile(BaseDate.AddMinutes(minutesToAdd));

            Assert.Equal(expected, shouldUpdate);
        }
コード例 #3
0
        public void WhenWritingInDifferentPeriod_CreateNewFile(bool async, RollingFilePeriod period, int[] minutesToAdd)
        {
            using (var temp = TempFolder.Create())
            {
                WriteLogs(async, temp.FolderPath, period, minutesToAdd);

                foreach (var minutes in minutesToAdd)
                {
                    var date         = BaseDate.AddMinutes(minutes);
                    var contentsFile = File.ReadAllLines(Path.Combine(temp.FolderPath, period.GetFileName(date)));
                    var log          = string.Format("{0} [DBG] date={1}", date.ToString(DefaultDateTimeFormat),
                                                     date.ToString(period.DateFormat));

                    Assert.Equal(log, contentsFile[0]);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Writes logs using a sink.
        /// </summary>
        /// <param name="async">Indicates whether the asynchronous sink should be created.</param>
        /// <param name="logFolderPath">Log files folder path.</param>
        /// <param name="period">Rolling file period.</param>
        /// <param name="minutesToAdd">Minutes to add for each writing.</param>
        private void WriteLogs(bool async, string logFolderPath, RollingFilePeriod period, int[] minutesToAdd)
        {
            foreach (var minutes in minutesToAdd)
            {
                var date = BaseDate.AddMinutes(minutes);
                timeProviderMock.Setup(m => m.CurrentDateTime).Returns(date);

                var sink    = CreateSink(async, logFolderPath, period);
                var entries = new List <ILogEntry>()
                {
                    new LogEntry("date", date.ToString(period.DateFormat))
                };

                sink.Write(GenericLogLevelName.Debug, entries);

                ((IDisposable)sink).Dispose();
            }
        }