public void FlightRecorder_Persist_Basic() { // Verify that the recorder can persist a couple of events // and then dequeue them. MemoryStream stream; byte[] serialized; stream = new MemoryStream(); using (var recorder = new FlightRecorder(stream)) { Assert.IsTrue(recorder.IsPersistMode); Assert.IsFalse(recorder.IsPassThruMode); recorder.Log("event #1"); recorder.Log("event #2"); serialized = stream.ToArray(); } stream = new MemoryStream(serialized); using (var recorder = new FlightRecorder(stream)) { Assert.AreEqual(2, recorder.Count); Assert.AreEqual("event #1", recorder.Dequeue().Operation); Assert.AreEqual(1, recorder.Count); Assert.AreEqual("event #2", recorder.Dequeue().Operation); Assert.AreEqual(0, recorder.Count); Assert.IsNull(recorder.Dequeue()); } }
public void FlightRecorder_Persist_SysLogProvider() { // Verify that the ISysLogProvider implementation works. ISysLogProvider orgProvider = SysLog.LogProvider; try { MemoryStream stream = new MemoryStream(); FlightEvent flightEvent; using (var recorder = new FlightRecorder(stream)) { SysLog.LogProvider = recorder; SysLog.LogError("Test Error"); SysLog.LogWarning("Test Warning"); SysLog.LogInformation("Test Information"); SysLog.Flush(); Assert.AreEqual(3, recorder.Count); flightEvent = recorder.Dequeue(); Assert.AreEqual("SysLog:Error", flightEvent.Operation); Assert.IsTrue(flightEvent.Details.Contains("Test Error")); Assert.IsTrue(flightEvent.IsError); flightEvent = recorder.Dequeue(); Assert.AreEqual("SysLog:Warning", flightEvent.Operation); Assert.IsTrue(flightEvent.Details.Contains("Test Warning")); Assert.IsFalse(flightEvent.IsError); flightEvent = recorder.Dequeue(); Assert.AreEqual("SysLog:Information", flightEvent.Operation); Assert.IsTrue(flightEvent.Details.Contains("Test Information")); Assert.IsFalse(flightEvent.IsError); // Verify that system events actually serialize exception // and stack trace related information. try { throw new AssertException(); } catch (Exception e) { SysLog.LogException(e); SysLog.Flush(); flightEvent = recorder.Dequeue(); Assert.AreEqual("SysLog:Exception", flightEvent.Operation); Assert.IsTrue(flightEvent.Details.Contains("AssertException")); } } } finally { SysLog.LogProvider = orgProvider; } }
public void FlightRecorder_Persist_EventFields() { // Verify that all event fields are persisted properly. MemoryStream stream; byte[] serialized; string organizationID = Guid.NewGuid().ToString(); string userID = Guid.NewGuid().ToString(); string sessionID = Guid.NewGuid().ToString(); FlightEvent flightEvent; stream = new MemoryStream(); using (var recorder = new FlightRecorder(stream)) { recorder.OrganizationID = null; recorder.UserID = null; recorder.SessionID = null; recorder.Source = null; recorder.SourceVersion = null; recorder.Log("event #1"); recorder.OrganizationID = organizationID; recorder.UserID = userID; recorder.SessionID = sessionID; recorder.Source = "test.app"; recorder.SourceVersion = new Version("1.2.3.4"); recorder.Log("event #2", "details", true); serialized = stream.ToArray(); } stream = new MemoryStream(serialized); using (var recorder = new FlightRecorder(stream)) { flightEvent = recorder.Dequeue(); Assert.IsNull(flightEvent.OrganizationID); Assert.IsNull(flightEvent.UserID); Assert.IsNull(flightEvent.SessionID); Assert.IsNull(flightEvent.Source); Assert.IsNull(flightEvent.SourceVersion); Assert.AreEqual("event #1", flightEvent.Operation); Assert.IsNull(flightEvent.Details); Assert.IsFalse(flightEvent.IsError); flightEvent = recorder.Dequeue(); Assert.AreEqual(organizationID, flightEvent.OrganizationID); Assert.AreEqual(userID, flightEvent.UserID); Assert.AreEqual(sessionID, flightEvent.SessionID); Assert.AreEqual("test.app", flightEvent.Source); Assert.AreEqual(new Version("1.2.3.4"), flightEvent.SourceVersion); Assert.AreEqual("event #2", flightEvent.Operation); Assert.AreEqual("details", flightEvent.Details); Assert.IsTrue(flightEvent.IsError); } }
public void FlightRecorder_Persist_Disabled() { // Verify that events are not logged when the recorder is disabled. MemoryStream stream; byte[] serialized; stream = new MemoryStream(); using (var recorder = new FlightRecorder(stream)) { Assert.IsTrue(recorder.IsPersistMode); Assert.IsFalse(recorder.IsPassThruMode); recorder.IsEnabled = false; recorder.Log("event XX"); recorder.IsEnabled = true; recorder.Log("event #1"); recorder.Log("event #2"); serialized = stream.ToArray(); } stream = new MemoryStream(serialized); using (var recorder = new FlightRecorder(stream)) { Assert.AreEqual(2, recorder.Count); Assert.AreEqual("event #1", recorder.Dequeue().Operation); Assert.AreEqual(1, recorder.Count); Assert.AreEqual("event #2", recorder.Dequeue().Operation); Assert.AreEqual(0, recorder.Count); Assert.IsNull(recorder.Dequeue()); } // Now verify that setting IsEnabled=false clears the recorder. stream = new MemoryStream(); using (var recorder = new FlightRecorder(stream)) { Assert.IsTrue(recorder.IsPersistMode); Assert.IsFalse(recorder.IsPassThruMode); recorder.Log("event #1"); recorder.IsEnabled = false; recorder.Log("event XX"); recorder.IsEnabled = true; recorder.Log("event #2"); Assert.AreEqual(1, recorder.Count); Assert.AreEqual("event #2", recorder.Dequeue().Operation); } }
public void FlightRecorder_Persist_Multiple() { // Verify that a second flight recorder trying to use the same // backing file will fail-over to using a memory stream. string path = Path.GetTempFileName(); try { using (var recorder1 = new FlightRecorder(path)) { Assert.IsTrue(recorder1.IsPersistMode); Assert.IsFalse(recorder1.IsPassThruMode); using (var recorder2 = new FlightRecorder(path)) { // Perform some operations to the second recorder. These // operations will be NOPs since the recorder is blocked, // but should not fail or impact the first recorder's // backing file. recorder2.Log("Test"); recorder2.Dequeue(); recorder2.Dequeue(2); recorder2.GetEvents(); // Record some events to the first recorder. recorder1.Log("event #1"); recorder1.Log("event #2"); } } // Verify that the first instance did record properly. using (var recorder = new FlightRecorder(path)) { Assert.AreEqual(2, recorder.Count); Assert.AreEqual("event #1", recorder.Dequeue().Operation); Assert.AreEqual(1, recorder.Count); Assert.AreEqual("event #2", recorder.Dequeue().Operation); Assert.AreEqual(0, recorder.Count); Assert.IsNull(recorder.Dequeue()); } } finally { Helper.DeleteFile(path); } }
public void FlightRecorder_Persist_MaxEvents() { // Verify that the record honors the MaxEvents property. MemoryStream stream = new MemoryStream(); FlightEvent flightEvent; using (var recorder = new FlightRecorder(stream)) { recorder.MaxEvents = 10; for (int i = 0; i < 20; i++) { recorder.Log(i.ToString()); } Assert.AreEqual(10, recorder.Count); flightEvent = recorder.Dequeue(); Assert.AreEqual("10", flightEvent.Operation); } }