Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// There is a bug in the 1.1.26 release of the package. The following code is taken from the documentation in http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-64-26-84/EventSourceRichPayloads.docx
- /// See the last 3 lines of the main method
- /// </summary>
- using Microsoft.Diagnostics.Tracing;
- using System.Collections.Generic;
- namespace DriveMappingTest
- {
- [EventData]
- public sealed class NodeData
- {
- public string NodeName { get; set; }
- public int NodeId { get; set; }
- public int[] ChildNodeIds { get; set; }
- public Dictionary<string, int> UserValues { get; set; }
- }
- [EventData]
- public sealed class SimpleData
- {
- public string Name { get; set; }
- public int Address { get; set; }
- }
- //[EventSource(Name = "Samples-EventSourceDemos-RuntimeDemo")]
- public sealed class RuntimeDemoEventSource : EventSource
- {
- // define the Load Event. Calling this method logs the event
- [NonEvent]
- public void LogSimpleData(string message, SimpleData data) { Write(message, data); }
- [NonEvent]
- public void LogArray(string message, IEnumerable<int> data) { Write(message, data); }
- [NonEvent]
- public void LogNode(string message, NodeData data) { Write(message, data); }
- [NonEvent]
- public void LogDictionary(string message, Dictionary<string, int> keyValues)
- { Write(message, keyValues); }
- // define the singleton instance of the event source
- public static RuntimeDemoEventSource Log = new RuntimeDemoEventSource();
- private RuntimeDemoEventSource() : base("EventSource-TestSource", EventSourceSettings.EtwSelfDescribingEventFormat) { }
- }
- /// <summary>
- /// The following code is taken from the documentation in http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-64-26-84/EventSourceRichPayloads.docx
- /// See the last 3 lines of the main method
- /// </summary>
- public class Test
- {
- static void Main(string[] args)
- {
- var aList = new List<int>() { 3, 4, 5, 6 };
- var aDictionary = new Dictionary<string, int>() { { "user1", 1 }, { "user2", 2 } };
- var aNode = new NodeData
- {
- NodeName = "Test",
- NodeId = 1,
- ChildNodeIds = new int[] { 3, 4, 5 },
- UserValues = aDictionary
- };
- // Logging the complex values above.
- RuntimeDemoEventSource.Log.LogArray("testMessage", aList); // EventSourceException: System.ArgumentNullException:This usually means that the object passed to Write is of a type that does not support being used as the top-level object in an event, e.g. a primitive or built-in type. Parameter name: name
- RuntimeDemoEventSource.Log.LogDictionary("testMessage", aDictionary); // EventSourceException: System.ArgumentNullException:This usually means that the object passed to Write is of a type that does not support being used as the top-level object in an event, e.g. a primitive or built-in type. Parameter name: name
- RuntimeDemoEventSource.Log.LogNode("testMessage", aNode); // Logged successfully.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement