Example #1
0
        public void MultipleFilesAreWrittenWhenUsingAsynchForRollingFlatFile()
        {
            const string Folder = "AsyncFolder";
            const string FileNameWithoutExtension = "AsynchTestingForRollingFlatFile";
            const string Extension = ".log";
            const string FileName  = FileNameWithoutExtension + Extension;

            LogFileReader.CreateDirectory(Folder);

            var configuration = new LoggingConfiguration();

            configuration.AddLogSource("TestAsynchLogging In RollingFlatFile").AddTraceListener(new AsynchronousTraceListenerWrapper(
                                                                                                    new RollingFlatFileTraceListener(Path.Combine(Folder, FileName), "----", "----", new TextFormatter(), 8, "yyyy",
                                                                                                                                     RollFileExistsBehavior.Increment, RollInterval.Minute, 10), ownsWrappedTraceListener: true, bufferSize: 100));

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

            Assert.IsTrue(File.Exists(Path.Combine(Folder, FileName)));
            Assert.IsTrue(File.Exists(Path.Combine(Folder, FileNameWithoutExtension + "." + DateTime.Now.Year + ".1" + Extension)));
            Assert.IsTrue(File.Exists(Path.Combine(Folder, FileNameWithoutExtension + "." + DateTime.Now.Year + ".5" + Extension)));
        }
        public void EmailIsSentWhenCategoriesSeverityVerbose()
        {
            LogFileReader.CreateDirectory("mail");

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

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);

            LogEntry entry = new LogEntry();

            entry.Categories.Add("General");
            entry.Message  = "Email Message Test";
            entry.EventId  = 123;
            entry.Priority = 11;
            entry.Severity = TraceEventType.Error;

            this.writer.Write(entry);

            Assert.IsNotNull(LogFileReader.GetEmail());
        }
 public override void TestInitialize()
 {
     this.strPath = @".\LogConfig" + Guid.NewGuid().ToString();
     LogFileReader.CreateDirectory(this.strPath);
 }
 public override void TestInitialize()
 {
     LogFileReader.CreateDirectory("mail");
 }