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); }
protected override void Given() { this.formatter = new MockFormatter(); this.inMemoryListener = new InMemoryEventListener(this.formatter); var sink = new Lazy<IObserver<EventEntry>>(() => this.inMemoryListener); this.sourceSettings = this.sourceSettings ?? new EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource))); this.eventSources = new List<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 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)); }