Ejemplo n.º 1
0
        [Ignore]    // TODO fix race condition
        public void ConcurrentAppendsEntriesToFlatFileWhenUsingAsync()
        {
            const int NumberOfEntries = 300;

            using (var sink = new RollingFlatFileSink(fileName, 0, "yyyy", RollFileExistsBehavior.Increment, RollInterval.Day, 0, new SimpleMessageFormatter(), isAsync: true))
            {
                Parallel.For(0, NumberOfEntries, i => sink.OnNext(EventEntryTestHelper.Create(formattedMessage: "|" + i)));
                sink.FlushAsync().Wait();
            }

            var entries = File.ReadAllText(fileName).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            Assert.AreEqual <int>(NumberOfEntries, entries.Length);
            for (int i = 0; i < NumberOfEntries; i++)
            {
                CollectionAssert.Contains(entries, i.ToString());
            }
        }
Ejemplo n.º 2
0
        public void WillRollExistingFileIfOverSizeThresholdAndNoPatternIsSpecifiedForIncrementBehaviorWhenUsingAsync()
        {
            string   existingPayload = new string('c', 5000);
            DateTime currentDateTime = new DateTime(2007, 1, 1);

            File.WriteAllText(fileName, existingPayload);
            File.SetCreationTime(fileName, currentDateTime);

            using (var sink
                       = new RollingFlatFileSink(fileName, 1, string.Empty, RollFileExistsBehavior.Increment, RollInterval.None, 0, new SimpleMessageFormatter(), isAsync: true))
            {
                sink.RollingHelper.DateTimeProvider   = dateTimeProvider;
                dateTimeProvider.CurrentDateTimeField = currentDateTime;

                sink.OnNext(EventEntryTestHelper.Create(formattedMessage: "logged message"));
                sink.FlushAsync().Wait();
            }

            Assert.AreEqual(existingPayload, File.ReadAllText(fileNameWithoutExtension + ".1" + Extension));
            Assert.IsTrue(File.ReadAllText(fileName).Contains("logged message"));
        }
Ejemplo n.º 3
0
        public void ConcurrentAppendsEntriesToFlatFileWhenUsingAsync()
        {
            const int NumberOfEntries = 300;

            using (var sink = new RollingFlatFileSink(fileName, 0, "yyyy", RollFileExistsBehavior.Increment, RollInterval.Day, 0, isAsync: true))
            {
                Parallel.For(0, NumberOfEntries, i => sink.OnNext("|" + i));
                sink.FlushAsync().Wait();
            }

            var entries = File.ReadAllText(fileName).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            Assert.AreEqual<int>(NumberOfEntries, entries.Length);
            for (int i = 0; i < NumberOfEntries; i++)
            {
                CollectionAssert.Contains(entries, i.ToString());
            }
        }
Ejemplo n.º 4
0
        public void WillRollExistingFileIfOverSizeThresholdAndNoPatternIsSpecifiedForIncrementBehaviorWhenUsingAsync()
        {
            string existingPayload = new string('c', 5000);
            DateTime currentDateTime = new DateTime(2007, 1, 1);
            File.WriteAllText(fileName, existingPayload);
            File.SetCreationTime(fileName, currentDateTime);

            using (var sink
                = new RollingFlatFileSink(fileName, 1, "", RollFileExistsBehavior.Increment, RollInterval.None, 0, isAsync: true))
            {
                sink.RollingHelper.DateTimeProvider = dateTimeProvider;
                dateTimeProvider.currentDateTime = currentDateTime;

                sink.OnNext("logged message");
                sink.FlushAsync().Wait();
            }

            Assert.AreEqual(existingPayload, File.ReadAllText(fileNameWithoutExtension + ".1" + extension));
            Assert.IsTrue(File.ReadAllText(fileName).Contains("logged message"));
        }