public void ClonedLogEntryHasNullErrorMessagesIfSourceLogEntryHasNullErrorMessages() { LogEntry entry = CommonUtil.GetDefaultLogEntry(); LogEntry entry2 = entry.Clone() as LogEntry; Assert.IsNotNull(entry2); Assert.IsNull(entry2.ErrorMessages); Assert.AreEqual(entry.ErrorMessages, entry2.ErrorMessages); }
public void LogSourceDoesAutoFlush() { MockFlushSensingTraceListener traceListener = new MockFlushSensingTraceListener(); List <TraceListener> listeners = new List <TraceListener>(1); listeners.Add(traceListener); LogSource logSource = new LogSource("name", listeners, SourceLevels.All, true); logSource.TraceData(TraceEventType.Critical, 0, CommonUtil.GetDefaultLogEntry()); Assert.AreEqual(1, traceListener.flushCalls); }
public void ConfirmCloneWorksWithICloneableExtendedProperties() { LogEntry entry = CommonUtil.GetDefaultLogEntry(); entry.ExtendedProperties = new Dictionary <string, object>(); entry.ExtendedProperties.Add("one", "two"); LogEntry entry2 = entry.Clone() as LogEntry; Assert.IsNotNull(entry2); Assert.AreEqual("two", entry2.ExtendedProperties["one"]); }
public void SendRegularLogEntryToCustomLogEntrySink() { SetInProcDistributionStrategy(); LogEntry logEntry = CommonUtil.GetDefaultLogEntry(); logEntry.Category = "CustomMessageCategory"; Logger.Write(logEntry); Assert.AreEqual(CustomLogEntrySink.Category, "CustomMessageCategory"); }
public void SendMessageWithPriorityBelowMinimum() { LogEntry logEntry = CommonUtil.GetDefaultLogEntry(); logEntry.Category = "MockCategoryOne"; logEntry.Priority = loggingSettings.MinimumPriority - 1; Logger.Write(logEntry); LogEntry resultLog = MockDistributionStrategy.Entry; Assert.IsNull(resultLog, "confirm that the message did NOT get logged by the strategy"); }
public void ClonedEntryGetsActivityId() { LogEntry entry = CommonUtil.GetDefaultLogEntry(); LogEntry entry2 = entry.Clone() as LogEntry; Assert.AreEqual(entry.ActivityId, entry2.ActivityId); entry.ActivityId = Guid.NewGuid(); LogEntry entry3 = entry.Clone() as LogEntry; Assert.AreEqual(entry.ActivityId, entry3.ActivityId); }
public void ConfirmCloningNonCloneableExtendedPropertiesReplacesExtendedPropertiesCollection() { LogEntry originalLogEntry = CommonUtil.GetDefaultLogEntry(); Dictionary <string, object> extendedProperties = new Dictionary <string, object>(); originalLogEntry.ExtendedProperties = extendedProperties; originalLogEntry.ExtendedProperties.Add("one", "two"); LogEntry clonedLogEntry = originalLogEntry.Clone() as LogEntry; Assert.IsNotNull(clonedLogEntry); Assert.IsFalse(ReferenceEquals(extendedProperties, clonedLogEntry.ExtendedProperties)); Assert.AreEqual(1, clonedLogEntry.ExtendedProperties.Count); }
public void ConfirmCloningNonCloneableExtendedPropertiesReplacesExtendedPropertiesCollection() { LogEntry entry = CommonUtil.GetDefaultLogEntry(); ListDictionary extendedProperties = new ListDictionary(); entry.ExtendedProperties = extendedProperties; entry.ExtendedProperties.Add("one", "two"); LogEntry entry2 = entry.Clone() as LogEntry; Assert.IsNotNull(entry2); Assert.IsFalse(object.ReferenceEquals(extendedProperties, entry2.ExtendedProperties)); Assert.AreEqual(0, entry2.ExtendedProperties.Count); }
public void SendMessageWithPriorityAboveMinimum() { LogEntry logEntry = CommonUtil.GetDefaultLogEntry(); logEntry.Category = "MockCategoryOne"; logEntry.Priority = loggingSettings.MinimumPriority + 1; Logger.Write(logEntry); LogEntry resultLog = MockDistributionStrategy.Entry; Assert.IsNotNull(resultLog, "confirm that the message got logged by the strategy"); Assert.AreEqual(logEntry.Message, resultLog.Message); }
public void WriteDictionary() { SetInProcDistributionStrategy(); LogEntry entry = CommonUtil.GetDefaultLogEntry(); entry.Category = "DictionaryCategory"; entry.ExtendedProperties = CommonUtil.GetPropertiesHashtable(); Logger.Write(entry); string expected = CommonUtil.FormattedMessageWithDictionary; string actual = CommonUtil.GetLastEventLogEntryCustom(); Assert.AreEqual(expected, actual); }
public void AddObjectAsContextItem() { ContextObject obj = new ContextObject(); Logger.SetContextItem("object", obj); LogEntry log = CommonUtil.GetDefaultLogEntry(); log.Categories = new string[] { "MockCategoryOne" }; log.Severity = TraceEventType.Error; Logger.Write(log); string result = ((LogEntry)MockTraceListener.LastEntry).ExtendedProperties["object"].ToString(); string expected = obj.ToString(); Assert.AreEqual(expected, result); }
public void AddObjectAsContextItem() { ContextObject obj = new ContextObject(); Logger.SetContextItem("object", obj); LogEntry log = CommonUtil.GetDefaultLogEntry(); log.Category = "MockCategoryOne"; Logger.Write(log); string result = MockLogSink.GetLastEntry().ExtendedProperties["object"].ToString(); string expected = obj.ToString(); Assert.AreEqual(expected, result); }
public void MessageLoggedWithPriorityBelowMinimumWillNotBeLogged() { LogEntry logEntry = CommonUtil.GetDefaultLogEntry(); logEntry.Categories = new string[] { "MockCategoryOne" }; logEntry.Priority = Logger.GetFilter <PriorityFilter>().MinimumPriority - 1; logEntry.Severity = TraceEventType.Information; bool shouldLog = Logger.ShouldLog(logEntry); Logger.Write(logEntry); LogEntry resultLog = MockTraceListener.LastEntry; Assert.IsNull(resultLog, "confirm that the message did NOT get logged by the strategy"); Assert.IsFalse(shouldLog); }
public void ClonedLogEntryHasEqualButNotSameErrorMessagesIfSourceLogEntryHasNotNullErrorMessages() { LogEntry entry = CommonUtil.GetDefaultLogEntry(); entry.AddErrorMessage("message 1"); entry.AddErrorMessage("message 2"); LogEntry entry2 = entry.Clone() as LogEntry; Assert.IsNotNull(entry2); Assert.IsNotNull(entry2.ErrorMessages); Assert.AreEqual(entry.ErrorMessages, entry2.ErrorMessages); Assert.IsTrue(entry.ErrorMessages.Equals(entry2.ErrorMessages)); entry2.AddErrorMessage("message 3"); Assert.IsFalse(entry.ErrorMessages.Equals(entry2.ErrorMessages)); }
public void MessageLoggedWithSufficientPriorityShouldGetLogged() { LogEntry logEntry = CommonUtil.GetDefaultLogEntry(); logEntry.Categories = new string[] { "MockCategoryOne" }; logEntry.Priority = Logger.GetFilter <PriorityFilter>().MinimumPriority + 1; logEntry.Severity = TraceEventType.Information; bool shouldLog = Logger.ShouldLog(logEntry); Logger.Write(logEntry); LogEntry resultLog = MockTraceListener.LastEntry; Assert.IsNotNull(resultLog, "confirm that the message got logged by the strategy"); Assert.AreEqual(logEntry.Message, resultLog.Message); Assert.IsTrue(shouldLog); }
public void ClonedEntryGetsClonedCategories() { string[] categories = new string[] { "cat1", "cat2", "cat3" }; LogEntry entry = CommonUtil.GetDefaultLogEntry(); entry.Categories = new List <string>(categories); LogEntry entry2 = entry.Clone() as LogEntry; Assert.IsNotNull(entry2); Assert.IsFalse(entry.Categories == entry2.Categories); Assert.AreEqual(entry.Categories.Count, entry2.Categories.Count); foreach (string category in categories) { Assert.IsTrue(entry2.Categories.Contains(category)); } }
public void CustomContextByteArrayObject() { Guid expectedGuid = Guid.NewGuid(); byte[] byteArray = expectedGuid.ToByteArray(); Logger.SetContextItem("bytes", byteArray); LogEntry log = CommonUtil.GetDefaultLogEntry(); log.Categories = new string[] { "MockCategoryOne" }; log.Severity = TraceEventType.Error; Logger.Write(log); string guidArray = ((LogEntry)MockTraceListener.LastEntry).ExtendedProperties["bytes"].ToString(); byteArray = Convert.FromBase64String(guidArray); Guid resultGuid = new Guid(byteArray); Assert.AreEqual(expectedGuid, resultGuid); }
public void EventLogWrittenWhenDeliveryToErrorSourceFails() { TraceListener badTraceListener = new BadTraceListener(new Exception("test exception")); LogSource badSource = new LogSource("badSource"); badSource.Listeners.Add(badTraceListener); Dictionary <string, LogSource> logSources = new Dictionary <string, LogSource>(); logSources.Add("foo", badSource); ILoggingInstrumentationProvider instrumentationProvider = new LoggingInstrumentationProvider(false, true, "applicationInstanceName"); LogWriter writer = new LogWriterImpl(new List <ILogFilter>(), logSources, badSource, "foo", instrumentationProvider); writer.Write(CommonUtil.GetDefaultLogEntry()); string lastEventLogEntry = CommonUtil.GetLastEventLogEntry(); Assert.IsTrue(-1 != lastEventLogEntry.IndexOf("test exception")); }
public void WriteDictionaryWithHeaderAndFooter() { LogEntry entry = CommonUtil.GetDefaultLogEntry(); entry.Categories = new string[] { "DictionaryCategoryForFlatFile" }; entry.Severity = TraceEventType.Error; entry.ExtendedProperties = CommonUtil.GetPropertiesDictionary(); Logger.Write(entry); Logger.Reset(); string expected = CommonUtil.FormattedMessageWithDictionary; string actual = GetFileContents(CommonUtil.FileName); Assert.IsTrue(actual.IndexOf("key1") > -1); Assert.IsTrue(actual.IndexOf("value1") > -1); Assert.IsTrue(actual.IndexOf("key2") > -1); Assert.IsTrue(actual.IndexOf("value2") > -1); Assert.IsTrue(actual.IndexOf("key3") > -1); Assert.IsTrue(actual.IndexOf("value3") > -1); }
public void UpdatesTraceEventCacheOnEachCall() { MockEventCacheSensingTraceListener traceListener1 = new MockEventCacheSensingTraceListener(); MockEventCacheSensingTraceListener traceListener2 = new MockEventCacheSensingTraceListener(); List <TraceListener> traceListeners = new List <TraceListener>(1); traceListeners.Add(traceListener1); traceListeners.Add(traceListener2); LogSource logSource = new LogSource("name", traceListeners, SourceLevels.All); logSource.TraceData(TraceEventType.Critical, 0, CommonUtil.GetDefaultLogEntry()); Assert.AreEqual(traceListener1.dateTime, traceListener2.dateTime); Assert.IsTrue(traceListener1.dateTime > default(DateTime)); DateTime savedDateTime = traceListener1.dateTime; Thread.Sleep(100); logSource.TraceData(TraceEventType.Critical, 0, CommonUtil.GetDefaultLogEntry()); Assert.AreEqual(traceListener1.dateTime, traceListener2.dateTime); Assert.IsTrue(traceListener1.dateTime > default(DateTime)); Assert.IsTrue(traceListener1.dateTime > savedDateTime); }
public void CustomContextByteArrayObject() { Guid expectedGuid = Guid.NewGuid(); byte[] byteArray = expectedGuid.ToByteArray(); Logger.SetContextItem("bytes", byteArray); LogEntry log = CommonUtil.GetDefaultLogEntry(); log.Category = "MockCategoryOne"; Logger.Write(log); // get body and parse out the byte array and go back to the guid form string guidArray = MockLogSink.GetLastEntry().ExtendedProperties["bytes"].ToString(); byteArray = Convert.FromBase64String(guidArray); Guid resultGuid = new Guid(byteArray); Assert.AreEqual(expectedGuid, resultGuid); }
public void LogSourceCallsFlushRegardlessOfAutoflushValue() { MockFlushSensingTraceListener traceListener = new MockFlushSensingTraceListener(); List <TraceListener> traceListeners = new List <TraceListener>(1); traceListeners.Add(traceListener); LogSource logSource = new LogSource("name", traceListeners, SourceLevels.All); bool currentAutoFlush = Trace.AutoFlush; try { Trace.AutoFlush = false; logSource.TraceData(TraceEventType.Critical, 0, CommonUtil.GetDefaultLogEntry()); Trace.AutoFlush = true; logSource.TraceData(TraceEventType.Critical, 0, CommonUtil.GetDefaultLogEntry()); Assert.AreEqual(2, traceListener.flushCalls); } finally { Trace.AutoFlush = currentAutoFlush; } }
public static void SendTestMessage(LogSink sink) { LogEntry logEntry = CommonUtil.GetDefaultLogEntry(); sink.SendMessage(logEntry); }