public void WhenCustomFormatterThrowsAnExceptionAndUsedConfig() { string fileName = "FlatFileOutProcCustomFormatterHandleExceptionViaConfig.log"; File.Delete(fileName); var logger = MockEventSourceOutProc.Logger; MockFormatter formatter = new MockFormatter(true); //this formatter throws TraceEventServiceConfiguration svcConfiguration = TraceEventServiceConfiguration.Load("Configurations\\CustomSink\\FlatFileCustomFormatter.xml"); TestScenario.WithConfiguration( svcConfiguration, () => { using (InMemoryEventListener collectErrorsListener = new InMemoryEventListener()) { try { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); logger.LogSomeMessage("some message using formatter that throws"); collectErrorsListener.WaitEvents.Wait(5000); StringAssert.Contains(collectErrorsListener.ToString(), "Payload : [message : System.InvalidOperationException: Operation is not valid due to the current state of the object."); } finally { collectErrorsListener.DisableEvents(SemanticLoggingEventSource.Log); } } }); }
public void WhenCustomFormatterThrowsAnExceptionAndUsedProgramatically() { string fileName = "FlatFileOutProcCustomFormatterHandleException.log"; File.Delete(fileName); var logger = MockEventSourceOutProc.Logger; MockFormatter formatter = new MockFormatter(true); //this formatter throws EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.Informational); var subject = new EventEntrySubject(); subject.LogToFlatFile(fileName, formatter); SinkSettings sinkSettings = new SinkSettings("flatFileSink", subject, new List<EventSourceSettings>() { { settings } }); List<SinkSettings> sinks = new List<SinkSettings>() { { sinkSettings } }; TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks); TestScenario.WithConfiguration( svcConfiguration, () => { using (var collectErrorsListener = new InMemoryEventListener()) { try { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.LogAlways, Keywords.All); logger.LogSomeMessage("some message using formatter that throws"); collectErrorsListener.WaitEvents.Wait(5000); StringAssert.Contains(collectErrorsListener.ToString(), "Payload : [message : System.InvalidOperationException: Operation is not valid due to the current state of the object."); } finally { collectErrorsListener.DisableEvents(SemanticLoggingEventSource.Log); } } }); }