public void EntryIsWrittenWhenXMLGeneralCategory()
        {
            File.Delete(Path.Combine(this.strPath, "XmlLogFile.xml"));

            LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace();

            this.UpdateConfigForXMLTL(loggingConfiguration);

            this.writer = new LogWriter(loggingConfiguration);
            this.writer.Write("Test Logging XML", "General");

            Assert.IsTrue(File.Exists(Path.Combine(this.strPath, "XmlLogFile.xml")));

            string strFileData = LogFileReader.ReadFileWithoutLock(Path.Combine(this.strPath, "XmlLogFile.xml"));

            Assert.IsTrue(strFileData.Contains("<Message>Test Logging XML</Message>"));
            Assert.IsTrue(strFileData.Contains("<Categories><String>General</String></Categories>"));
        }
Exemple #2
0
        public void AllEntriesAreWrittenWhenUsingAsynchForFlatFile()
        {
            string fileName = "AsynchTestingConfigForFlatFile.log";

            File.Delete(fileName);

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration2"));

            using (var writer = factory.Create())
            {
                Parallel.Invoke(Enumerable.Range(0, 2000).Select(i =>
                                                                 new Action(() =>
                {
                    writer.Write("Test Asynch Message Config: " + i);
                })).ToArray());
            }

            Assert.IsTrue(File.Exists(fileName));
            Assert.IsTrue(LogFileReader.ReadFileWithoutLock(fileName).Contains("Test Asynch Message Config: 0"));
            Assert.IsTrue(LogFileReader.ReadFileWithoutLock(fileName).Contains("Test Asynch Message Config: 1999"));
        }
Exemple #3
0
        public void AllEntriesAreWrittenWhenUsingAsynchForXMLWithDisposeTimeoutShortTimespan()
        {
            string xmlFileName = "XMLFileShortTimespan.xml";

            File.Delete(xmlFileName);

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration6"));

            using (var writer = factory.Create())
            {
                Parallel.Invoke(Enumerable.Range(0, 10000).Select(i =>
                                                                  new Action(() =>
                {
                    writer.Write("Test Asynch Message Config: " + i);
                })).ToArray());
            }

            Assert.IsTrue(File.Exists(xmlFileName));
            Assert.IsTrue(LogFileReader.ReadFileWithoutLock(xmlFileName).Contains("Test Asynch Message Config: 0"));
            Assert.IsTrue(LogFileReader.ReadFileWithoutLock(xmlFileName).Contains("Test Asynch Message Config: 9999"));
        }
        public void EntryIsWrittenAndOneFileExistsWhenRollingFlatFileGeneralCategoryOverwrite()
        {
            LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace();

            this.UpdateConfigForRollingFlatFileRollExistsOverwrite(loggingConfiguration);

            this.writer = new LogWriter(loggingConfiguration);
            for (int i = 0; i < 10; i++)
            {
                this.writer.Write("Test Logging Rolling " + i.ToString());
            }
            this.writer.Dispose();

            Assert.AreEqual(1, Directory.GetFiles(this.strPath).Length);
            Assert.IsTrue(File.Exists(Path.Combine(this.strPath, "RollingFlatFile.log")));

            string strFileData = LogFileReader.ReadFileWithoutLock(Path.Combine(this.strPath, "RollingFlatFile.log"));

            Assert.IsTrue(strFileData.Contains("Message: Test Logging Rolling 8"));
            Assert.IsTrue(strFileData.Contains("Message: Test Logging Rolling 9"));
            Assert.IsTrue(strFileData.Contains("Category: General"));
        }
        public void OnlyEntriesInPriorityRangeAreWrittenWhenRollingFlatFilePriorityFilter()
        {
            LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace();

            this.UpdateConfigForRollingFlatFileRollExistsIncrement(loggingConfiguration);

            var priorityFilter = new PriorityFilter("Priority Filter", 2, 99);

            loggingConfiguration.Filters.Add(priorityFilter);

            this.writer = new LogWriter(loggingConfiguration);
            this.writer.Write("Test Logging1", "General", 1);
            this.writer.Write("Test Logging2", "General", 2);
            this.writer.Write("Test Logging101", "General", 101);
            this.writer.Dispose();

            Assert.IsTrue(File.Exists(Path.Combine(this.strPath, "RollingFlatFile.log")));

            string strFileData = LogFileReader.ReadFileWithoutLock(Path.Combine(this.strPath, "RollingFlatFile.log"));

            Assert.IsFalse(strFileData.Contains("Message: Test Logging1"));
            Assert.IsFalse(strFileData.Contains("Message: Test Logging101"));
            Assert.IsTrue(strFileData.Contains("Message: Test Logging2"));
        }
Exemple #6
0
        public void MultipleEntriesAreWrittenWhenUsingAsynchForXML()
        {
            string xmlFileName = "XMLFile.xml";

            File.Delete(xmlFileName);

            var configuration = new LoggingConfiguration();

            configuration.AddLogSource("TestAsynchLogging In XML file").AddTraceListener(new AsynchronousTraceListenerWrapper(
                                                                                             new XmlTraceListener(xmlFileName), ownsWrappedTraceListener: true, bufferSize: 100));

            using (var writer = new LogWriter(configuration))
            {
                Parallel.Invoke(Enumerable.Range(0, 200).Select(i =>
                                                                new Action(() =>
                {
                    writer.Write("Test Asynch Message: " + i);
                })).ToArray());
            }

            Assert.IsTrue(File.Exists(xmlFileName));
            Assert.IsTrue(LogFileReader.ReadFileWithoutLock(xmlFileName).Contains("Test Asynch Message: 0"));
            Assert.IsTrue(LogFileReader.ReadFileWithoutLock(xmlFileName).Contains("Test Asynch Message: 99"));
        }
Exemple #7
0
        public void AllEntriesAreWrittenWhenUsingAsynchForFlatFile()
        {
            string fileName = "AsynchTestingForFlatFile.log";

            File.Delete(fileName);

            var configuration = new LoggingConfiguration();

            configuration.AddLogSource("TestAsynchLogging In FlatFile").AddTraceListener(new AsynchronousTraceListenerWrapper(
                                                                                             new FlatFileTraceListener(fileName), ownsWrappedTraceListener: true, bufferSize: 10000, disposeTimeout: TimeSpan.FromSeconds(5)));

            using (var writer = new LogWriter(configuration))
            {
                Parallel.Invoke(Enumerable.Range(0, 10000).Select(i =>
                                                                  new Action(() =>
                {
                    writer.Write("Test Asynch Message: " + i);
                })).ToArray());
            }

            Assert.IsTrue(File.Exists(fileName));
            Assert.IsTrue(LogFileReader.ReadFileWithoutLock(fileName).Contains("Test Asynch Message: 0"));
            Assert.IsTrue(LogFileReader.ReadFileWithoutLock(fileName).Contains("Test Asynch Message: 9999"));
        }