public void TestRawEventRecordEnvelope_GivenJsonFormat_FallsBackToEventRecordEnvelopeBehavior() { using (var eventReader = new EventLogReader("Application", PathType.LogName)) { EventLog.WriteEntry(LogSource, "Test message", EventLogEntryType.Information, 0); EventRecord eventRecord = null; do { System.Threading.Thread.Sleep(100); eventRecord = eventReader.ReadEvent(); } while (eventRecord == null); var envelope = new RawEventRecordEnvelope(eventRecord, true, 0); var jsonStr = envelope.GetMessage("json"); var jsonObj = JObject.Parse(jsonStr); Assert.NotNull(jsonObj); Assert.NotNull(jsonObj["EventId"]); Assert.NotNull(jsonObj["LevelDisplayName"]); Assert.NotNull(jsonObj["LogName"]); Assert.NotNull(jsonObj["MachineName"]); Assert.NotNull(jsonObj["ProviderName"]); Assert.NotNull(jsonObj["TimeCreated"]); Assert.NotNull(jsonObj["Description"]); Assert.NotNull(jsonObj["Index"]); Assert.NotNull(jsonObj["UserName"]); Assert.NotNull(jsonObj["Keywords"]); } }
public void TestRenderedXmlFormatRawRecordEnvelope() { using (var eventReader = new EventLogReader("Application", PathType.LogName)) { EventLog.WriteEntry(LogSource, "Test message", EventLogEntryType.Information, 0); EventRecord eventRecord = null; do { System.Threading.Thread.Sleep(100); eventRecord = eventReader.ReadEvent(); } while (eventRecord == null); var envelop = new RawEventRecordEnvelope(eventRecord, true, 0); var renderedXml = envelop.GetMessage("RenderedXml"); var xml = XElement.Parse(renderedXml); var renderingInfo = xml.Element(xml.Name.Namespace + "RenderingInfo"); Assert.NotNull(renderingInfo); Assert.NotNull(renderingInfo.Element(xml.Name.Namespace + "Message")); Assert.NotNull(renderingInfo.Element(xml.Name.Namespace + "Level")); Assert.NotNull(renderingInfo.Element(xml.Name.Namespace + "Task")); Assert.NotNull(renderingInfo.Element(xml.Name.Namespace + "Opcode")); Assert.NotNull(renderingInfo.Element(xml.Name.Namespace + "Channel")); Assert.NotNull(renderingInfo.Element(xml.Name.Namespace + "Provider")); Assert.NotNull(renderingInfo.Element(xml.Name.Namespace + "Keywords")); } }