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); } } }); }
protected override void Given() { TraceEventManifestsCache.Clear(); this.formatter = new MockFormatter(); this.inMemoryListener = new InMemoryEventListener(this.formatter); var sink = new Lazy <IObserver <EventEntry> >(() => this.inMemoryListener); this.sourceSettings = this.sourceSettings ?? new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource))); this.eventSources = new List <SemanticLogging.Etw.Configuration.EventSourceSettings> { this.sourceSettings }; this.sinkSettings = new List <SinkSettings> { new SinkSettings("test", sink, this.eventSources) }; this.configuration = new TraceEventServiceConfiguration(sinkSettings, this.serviceSettings); try { this.sut = new TraceEventService(configuration); } catch (UnauthorizedAccessException uae) { Assert.Inconclusive(uae.Message); } // Clean up any previous unclosed session to avoid collisions this.RemoveAnyExistingSession(); }
public void BaseFormatterConstructorShouldSetProperties() { MockFormatter formatter; formatter = new MockFormatter(null); Assert.IsNull(formatter.Configuration); MockFormatterElement configuration = new MockFormatterElement(); formatter = new MockFormatter(configuration); Assert.IsNotNull(formatter.Configuration); Assert.AreSame(configuration, formatter.Configuration); }
public void AppendsEntriesFromDifferentSourcesToFlatFile() { var formatter = new MockFormatter(); listener.LogToFlatFile(this.fileName, formatter); listener.EnableEvents(Logger, EventLevel.LogAlways, EventKeywords.None); listener.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All); Logger.Informational("From TestEventSource"); Logger.EventWithoutPayloadNorMessage(); MyCompanyEventSource.Log.PageStart(5, "http://test"); Assert.AreEqual <int>(3, formatter.WriteEventCalls.Count); }
public void AppendsEntriesFromDifferentSourcesUsesCorrectSchema() { var formatter = new MockFormatter(); listener.LogToFlatFile(this.fileName, formatter); listener.EnableEvents(Logger, EventLevel.LogAlways, EventKeywords.None); listener.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All); Logger.Informational("From TestEventSource"); Logger.EventWithoutPayloadNorMessage(); MyCompanyEventSource.Log.PageStart(5, "http://test"); Assert.AreEqual(EventSourceSchemaCache.Instance.GetSchema(TestEventSource.InformationalEventId, Logger), formatter.WriteEventCalls[0].Schema); Assert.AreEqual(EventSourceSchemaCache.Instance.GetSchema(TestEventSource.EventWithoutPayloadNorMessageId, Logger), formatter.WriteEventCalls[1].Schema); Assert.AreEqual(EventSourceSchemaCache.Instance.GetSchema(3, MyCompanyEventSource.Log), formatter.WriteEventCalls[2].Schema); }
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); } } }); }
public void AppendsEntriesToFlatFileWithNoInvalidEntries() { var formatter = new MockFormatter() { AfterWriteEventAction = (f) => { if (f.WriteEventCalls.Count == 1) { throw new InvalidOperationException(); } } }; listener.LogToFlatFile(this.fileName, formatter); listener.EnableEvents(Logger, EventLevel.LogAlways); Logger.Informational("Will throw error"); Logger.Informational("Valid message"); Assert.AreEqual("Valid message", ReadFileWithoutLock(this.fileName)); }