public void CustomListenerIsInvokedWhenConfigured() { const string ListenerName = "Custom Listener"; const string FormatterName = "Text Formatter"; const string Template = "My template"; configurationStart.LogToCategoryNamed(CategoryName) .WithOptions .DoNotAutoFlushEntries() .SetAsDefaultCategory() .ToSourceLevels(SourceLevels.All) .SendTo .Custom(ListenerName, typeof(MyCustomTraceListener)) .WithTraceOptions(TraceOptions.DateTime) .Filter(SourceLevels.Verbose) .FormatWith(new FormatterBuilder() .TextFormatterNamed(FormatterName) .UsingTemplate(Template)); this.SetConfigurationSource(); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(e)); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); LogEntry entry = LogEntryFactory.GetLogEntry(); entry.Categories.Add(LoggingFixtureBase.CategoryName); this.writer.Write(entry); Assert.IsTrue(MyCustomTraceListener.Wrote); }
public void EntryIsWrittenWhenLoggingWithXmlFile() { const string FilePath = "sample.xml"; const string ListenerName = "Xml File Listener"; File.Delete(FilePath); configurationStart.LogToCategoryNamed(CategoryName) .WithOptions .SetAsDefaultCategory() .ToSourceLevels(SourceLevels.All) .SendTo .XmlFile(ListenerName) .ToFile(FilePath) .WithTraceOptions(TraceOptions.None); this.SetConfigurationSource(); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(e)); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); LogEntry entry = LogEntryFactory.GetLogEntry(); entry.Categories.Add(CategoryName); writer.Write(entry); FileInfo info = new FileInfo(FilePath); Assert.IsTrue(info.Exists); Assert.IsTrue(info.Length > 0); }
public void WhenCategoryFilterIsChanged() { string fileName = "trace.log"; File.Delete(fileName); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration72")); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); var entry = LogEntryFactory.GetLogEntry(); entry.Severity = System.Diagnostics.TraceEventType.Critical; entry.Categories.Clear(); entry.Categories.Add("General"); this.writer.Write(entry); FileInfo info = new FileInfo(fileName); Assert.IsTrue(info.Exists); long originalLength = info.Length; this.ReplaceCategoryFilter("General"); this.writer.Write(entry); info = new FileInfo(fileName); Assert.IsTrue(info.Length == originalLength); }
public void EntryIsLoggedWhenLoggingLevelIsChanged() { string fileName = "trace.log"; File.Delete(fileName); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration72")); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); var entry = LogEntryFactory.GetLogEntry(); entry.Severity = System.Diagnostics.TraceEventType.Verbose; entry.Categories.Clear(); entry.Categories.Add("General"); this.writer.Write(entry); FileInfo info = new FileInfo(fileName); Assert.IsFalse(info.Exists); this.SetSourceLevel("General", SourceLevels.Critical); entry.Severity = TraceEventType.Critical; this.writer.Write(entry); info = new FileInfo(fileName); Assert.IsTrue(info.Exists); Assert.IsTrue(info.Length > 0); }
public void ArchiveFilesExistWhenLoggingMultipleEntriesWithRollingFlatFileTraceListener() { if (Directory.Exists("RFFLogFiles")) { Directory.Delete("RFFLogFiles", true); } LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration99")); this.writer = factory.Create(); for (int i = 0; i < 18; i++) { LogEntry entry = LogEntryFactory.GetLogEntry("RFFRoleOnSize", this.GetTwoKBMessage()); this.writer.Write(entry); } this.writer.Dispose(); Assert.AreEqual(5, Directory.GetFiles(".\\RFFLogFiles", "Log3*.log", SearchOption.TopDirectoryOnly).Length); Assert.IsTrue(File.Exists(Path.Combine("RFFLogFiles", String.Format("log3.{0}.14.log", DateTime.Now.Year)))); Assert.IsTrue(File.Exists(Path.Combine("RFFLogFiles", String.Format("log3.{0}.15.log", DateTime.Now.Year)))); Assert.IsTrue(File.Exists(Path.Combine("RFFLogFiles", String.Format("log3.{0}.16.log", DateTime.Now.Year)))); Assert.IsTrue(File.Exists(Path.Combine("RFFLogFiles", String.Format("log3.{0}.17.log", DateTime.Now.Year)))); }
public void EntryIsWrittenWhenLoggingUsingEventLog() { const string ListenerName = "Event Log Listener"; const string FormatterName = "Text Formatter"; const string Template = "My template"; configurationStart.WithOptions .LogToCategoryNamed(CategoryName) .WithOptions .SetAsDefaultCategory() .ToSourceLevels(SourceLevels.All) .SendTo .EventLog(ListenerName) .WithTraceOptions(TraceOptions.None) .FormatWith(new FormatterBuilder() .TextFormatterNamed(FormatterName) .UsingTemplate(Template)); this.SetConfigurationSource(); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(e)); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); LogEntry logEntry = LogEntryFactory.GetLogEntry(); this.writer.Write(logEntry); Assert.IsTrue(this.CheckForEntryInEventlog(Template)); }
public void EntryIsWrittenWhenEventLogTraceListenerMin() { bool entrymade = false; LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration68")); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); var entry = LogEntryFactory.GetLogEntry(); this.writer.Write(entry); EventLog events = new EventLog() { Log = "Application", Source = "Enterprise Library Logging" }; foreach (EventLogEntry elogentry in events.Entries) { if (elogentry.Message.Contains("Message: Sample Message.")) { entrymade = true; break; } } if (entrymade == false) { Assert.Fail("Eventlog message not logged"); } }
public void EntryIsWrittenWhenLoggingUsingBinaryLogFormatter() { const string BinaryFileName = "trace.log"; File.Delete(BinaryFileName); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration102")); this.writer = factory.Create(); LogEntry entry = LogEntryFactory.GetLogEntry(); entry.Categories.Clear(); entry.Categories.Add("General"); if (writer.ShouldLog(entry)) { this.writer.Write(entry); } Assert.IsTrue(File.Exists(BinaryFileName)); FileInfo fileInfo = new FileInfo(BinaryFileName); Assert.IsTrue(fileInfo.Length > 0); LogEntry deserializedEntry = LogFileReader.GetEntry(BinaryFileName); Assert.AreEqual(entry.Message, deserializedEntry.Message); Assert.AreEqual(entry.Priority, deserializedEntry.Priority); Assert.AreEqual(entry.Severity, deserializedEntry.Severity); }
public void ShouldNotLogWhenDeniedCategory() { LogEntry entry = LogEntryFactory.GetLogEntry(); entry.Categories.Clear(); entry.Categories.Add("Denied"); Assert.IsFalse(writer.ShouldLog(entry)); }
public void EntryIsWrittenWhenMinMSMQTraceListener() { LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration57")); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); var entry = LogEntryFactory.GetLogEntry(); this.writer.Write(entry); }
public void EntryIsWrittenWhenUnprocessedCategoryEventLog() { var entry = LogEntryFactory.GetLogEntry(); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration92")); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); this.writer.Write(entry); Assert.IsTrue(this.CheckForEntryInEventlog("Message: Sample Message.")); }
public void EntryIsWrittenWhenSpecialCategoriesCriticalEventLogMax() { LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration76")); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); var entry = LogEntryFactory.GetLogEntry(); this.writer.Write(entry); Assert.IsTrue(this.CheckForEntryInEventlog("Message: Sample Message.")); }
public void EntryIsWrittenWhenMinXMLTraceListener() { this.LoadConfig("loggingConfiguration50"); var entry = LogEntryFactory.GetLogEntry(); this.writer.Write(entry); FileInfo info = new FileInfo(XmlFilePath); Assert.IsTrue(info.Exists); Assert.IsTrue(info.Length > 0); }
public void ShouldOnlyLogWhenAllowedCategoryInCategories() { LogEntry entry = LogEntryFactory.GetLogEntry(); entry.Categories.Clear(); entry.Categories.Add("RFFBehavIncrTimeStampEmpty"); Assert.IsFalse(Logger.ShouldLog(entry)); entry.Categories.Add("General"); Assert.IsTrue(Logger.ShouldLog(entry)); }
public void CustomFormatterIsInvoked() { var listener = this.writer.TraceSources.Values.SelectMany(x => x.Listeners).OfType <MyCustomTraceListener>().Single(); var customFormatter = listener.Formatter as CustomFormatter; Assert.IsFalse(customFormatter.FormattedInvoked); this.writer.Write(LogEntryFactory.GetLogEntry()); Assert.IsTrue(customFormatter.FormattedInvoked); }
public void EntryIsWrittenWhenFlatFileTraceListenerMax() { LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration66")); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); var entry = LogEntryFactory.GetLogEntry(); this.writer.Write(entry); FileInfo info = new FileInfo("trace.log"); Assert.IsTrue(info.Exists); Assert.IsTrue(info.Length > 0); }
public void EntryIsWrittenWhenLogErrorsWarningsRollingFlatFile() { LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration97")); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); var entry = LogEntryFactory.GetLogEntry(); this.writer.Write(entry); FileInfo info = new FileInfo("rolling.log"); Assert.IsTrue(info.Exists); Assert.IsTrue(info.Length > 0); }
public void CustomTraceListenerIsInvoked() { MyCustomTraceListener.Wrote = false; MyCustomTraceListener.WroteLine = false; var listener = this.writer.TraceSources.Values.SelectMany(x => x.Listeners).OfType <MyCustomTraceListener>().Single(); Assert.IsFalse(MyCustomTraceListener.Wrote); LogEntry entry = LogEntryFactory.GetLogEntry(); entry.Categories.Add("General"); this.writer.Write(entry); Assert.IsTrue(MyCustomTraceListener.Wrote); }
public void EntryIsWrittenWhenLoggingAnEntryUsingXmlTraceListener() { File.Delete(XmlFilePath); this.LoadConfig("loggingConfiguration50"); var entry = LogEntryFactory.GetLogEntry(); entry.Categories.Clear(); entry.Categories.Add("General"); this.writer.Write(entry); FileInfo info = new FileInfo(XmlFilePath); Assert.IsTrue(info.Exists); Assert.IsTrue(info.Length > 0); }
public void EntryIsWrittenWhenLoggingUsingRollingFile() { const string FilePath = "rolling-sample.log"; const string ListenerName = "Rolling File Listener"; const string FormatterName = "Text Formatter"; const string Template = "My template"; const string Footer = "Footer"; const string Header = "Header"; File.Delete(FilePath); configurationStart.WithOptions .LogToCategoryNamed(CategoryName) .WithOptions .SetAsDefaultCategory() .ToSourceLevels(SourceLevels.All) .SendTo .RollingFile(ListenerName) .ToFile(FilePath) .RollAfterSize(100) .RollEvery(Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollInterval.Day) .UseTimeStampPattern("ddmmyyyy") .CleanUpArchivedFilesWhenMoreThan(5) .WithFooter(Footer) .WithHeader(Header) .WithTraceOptions(TraceOptions.None) .FormatWith(new FormatterBuilder() .TextFormatterNamed(FormatterName) .UsingTemplate(Template)); this.SetConfigurationSource(); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(e)); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); this.writer.Write(LogEntryFactory.GetLogEntry()); FileInfo info = new FileInfo(FilePath); Assert.IsTrue(info.Exists); Assert.IsTrue(info.Length > 0); }
public void EntryIsWrittenWhenLoggingWithBinaryFormatterUsingRollingFile() { const string FilePath = "rolling-sampleBinary.log"; const string ListenerName = "Rolling File Listener"; const string FormatterName = "Binary Formatter"; const string Footer = "----------------"; const string Header = "----------------"; File.Delete(FilePath); configurationStart.WithOptions .LogToCategoryNamed(CategoryName) .WithOptions .SetAsDefaultCategory() .ToSourceLevels(SourceLevels.All) .SendTo .RollingFile(ListenerName) .ToFile(FilePath) .RollAfterSize(100) .RollEvery(Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollInterval.Day) .UseTimeStampPattern("ddmmyyyy") .CleanUpArchivedFilesWhenMoreThan(5) .WithFooter(Footer) .WithHeader(Header) .WithTraceOptions(TraceOptions.None) .FormatWith(new FormatterBuilder() .BinaryFormatterNamed(FormatterName)); this.SetConfigurationSource(); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(e)); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); this.writer.Write(LogEntryFactory.GetLogEntry()); var deserializedEntry = LogFileReader.GetEntry(FilePath); Assert.AreEqual(LogEntryFactory.DefaultMessage, deserializedEntry.Message); Assert.AreEqual(2, deserializedEntry.Categories.Count); Assert.AreEqual(LogEntryFactory.DefaultEventId, deserializedEntry.EventId); Assert.AreEqual(LogEntryFactory.DefaultPriority, deserializedEntry.Priority); }
public void EntryIsWrittenWhenNoTransaction() { TimeSpan timeToBeReceived = TimeSpan.FromDays(1); TimeSpan timeToReachQueue = TimeSpan.Parse("49710.06:28:15"); System.Messaging.MessageQueueTransactionType trxType = System.Messaging.MessageQueueTransactionType.None; configurationStart.LogToCategoryNamed(CategoryName) .WithOptions .SetAsDefaultCategory() .ToSourceLevels(SourceLevels.All) .SendTo .Msmq(ListenerName) .UseQueue(QueuePath) .AsRecoverable() .Prioritize(MessagePriority) .UseDeadLetterQueue() .WithTransactionType(trxType) .SetTimeToBeReceived(timeToBeReceived) .SetTimeToReachQueue(timeToReachQueue) .WithTraceOptions(TraceOptions.None) .Filter(SourceLevels.Verbose) .FormatWith(new FormatterBuilder() .TextFormatterNamed(FormatterName) .UsingTemplate(Template)); this.SetConfigurationSource(); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(LoggingSettings.SectionName)); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); LogEntry entry = LogEntryFactory.GetLogEntry(CategoryName, "Test Message"); this.writer.Write(entry); string entryText = MsmqUtil.GetLogEntryFromQueue(); Assert.IsTrue(entryText == "<?xml version=\"1.0\"?>\r\n<string>My template</string>"); }
public void EntryIsWrittenWhenXmlLoggerWrites() { File.Delete(XmlFilePath); this.LoadConfig("loggingConfiguration50"); LogEntry entry = LogEntryFactory.GetLogEntry(); entry.Categories.Clear(); entry.Categories.Add("General"); Logger.Write(entry); var logEntryXDocument = LogFileReader.GetEntriesXml(XmlFilePath); string eventId = logEntryXDocument.Descendants( XName.Get("EventID", @"http://schemas.microsoft.com/2004/06/windows/eventlog/system")) .First().Value; Assert.IsNotNull(eventId == entry.EventId.ToString()); }
public void EntryIsNotWrittenWhenTransactionalQueueAndNoTransaction() { MsmqUtil.ValidateMsmqIsRunning(); MsmqUtil.DeletePrivateTestQ(); MsmqUtil.CreatePrivateTestQ(); System.Messaging.MessagePriority messagePriority = System.Messaging.MessagePriority.Lowest; System.Messaging.MessageQueueTransactionType trxType = System.Messaging.MessageQueueTransactionType.Single; const string QueuePath = MsmqUtil.MessageQueuePath; configurationStart.LogToCategoryNamed(CategoryName) .WithOptions .SetAsDefaultCategory() .ToSourceLevels(SourceLevels.All) .SendTo .Msmq(ListenerName) .UseQueue(QueuePath) .AsRecoverable() .Prioritize(messagePriority) .UseDeadLetterQueue() .WithTransactionType(trxType) .WithTraceOptions(TraceOptions.None) .Filter(SourceLevels.Verbose) .FormatWith(new FormatterBuilder() .TextFormatterNamed(FormatterName) .UsingTemplate(Template)); this.SetConfigurationSource(); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(LoggingSettings.SectionName)); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); LogEntry entry = LogEntryFactory.GetLogEntry(CategoryName, "Test Message"); this.writer.Write(entry); Assert.IsNull(MsmqUtil.GetLogEntryFromQueue()); }
public void EntryIsWrittenWhenLoggingWithBinaryFormatterUsingFlatFile() { const string FilePath = "binaryTemplateSample.log"; const string ListenerName = "Flat File Listener"; const string FormatterName = "Binary Formatter"; const string Footer = "-----------------"; const string Header = "-----------------"; File.Delete(FilePath); configurationStart.WithOptions .LogToCategoryNamed(CategoryName) .WithOptions .SetAsDefaultCategory() .ToSourceLevels(SourceLevels.All) .SendTo .FlatFile(ListenerName) .ToFile(FilePath) .WithFooter(Footer) .WithHeader(Header) .WithTraceOptions(TraceOptions.None) .FormatWith(new FormatterBuilder() .BinaryFormatterNamed(FormatterName)); this.SetConfigurationSource(); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(e)); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); this.writer.Write(LogEntryFactory.GetLogEntry()); var deserializedEntry = LogFileReader.GetEntry(FilePath); Assert.AreEqual(LogEntryFactory.DefaultMessage, deserializedEntry.Message); Assert.AreEqual(2, deserializedEntry.Categories.Count); Assert.AreEqual(LogEntryFactory.DefaultEventId, deserializedEntry.EventId); Assert.AreEqual(LogEntryFactory.DefaultPriority, deserializedEntry.Priority); }
public void EntryIsWrittenWhenLoggingUsingFlatFile() { const string FilePath = "sample.log"; const string ListenerName = "Flat File Listener"; const string FormatterName = "Text Formatter"; const string Template = "My template"; const string Footer = "Footer"; const string Header = "Header"; File.Delete(FilePath); configurationStart.WithOptions .LogToCategoryNamed(CategoryName) .WithOptions .SetAsDefaultCategory() .ToSourceLevels(SourceLevels.All) .SendTo .FlatFile(ListenerName) .ToFile(FilePath) .WithFooter(Footer) .WithHeader(Header) .WithTraceOptions(TraceOptions.None) .FormatWith(new FormatterBuilder() .TextFormatterNamed(FormatterName) .UsingTemplate(Template)); this.SetConfigurationSource(); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(e)); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); this.writer.Write(LogEntryFactory.GetLogEntry()); FileInfo info = new FileInfo(FilePath); Assert.IsTrue(info.Exists); Assert.IsTrue(info.Length > 0); }
public void EntryIsWrittenWhenLoggerWritesALogEntry() { File.Delete(TraceFileName); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration101")); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); LogEntry entry = LogEntryFactory.GetLogEntry(); entry.Categories.Clear(); entry.Categories.Add("General"); Logger.Write(entry); Assert.IsTrue(File.Exists(TraceFileName)); FileInfo fileInfo = new FileInfo(TraceFileName); Assert.IsTrue(fileInfo.Length > 0); }
public void EntryIsWrittenWhenMaxMSMQTraceListener() { MsmqUtil.ValidateMsmqIsRunning(); MsmqUtil.DeletePrivateTestQ(); MsmqUtil.CreatePrivateTestQ(); LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration63")); this.writer = factory.Create(); Logger.SetLogWriter(this.writer); var entry = LogEntryFactory.GetLogEntry(); entry.Categories.Add("General"); this.writer.Write(entry); this.writer.Dispose(); string entryText = MsmqUtil.GetLogEntryFromQueue(); Assert.IsTrue(entryText.Contains(entry.Message)); }