|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Diagnostics.Tracing; |
| 4 | +using System.Linq; |
| 5 | +using System.Runtime.InteropServices; |
| 6 | +using System.Text; |
| 7 | +using System.Threading.Tasks; |
| 8 | +using PostSharp.Patterns.Diagnostics; |
| 9 | +using PostSharp.Patterns.Diagnostics.Backends.EventSource; |
| 10 | + |
| 11 | +namespace PostSharp.Samples.Logging.Etw.CustomSource |
| 12 | +{ |
| 13 | + [Log(AttributeExclude = true)] |
| 14 | + [EventSource(Name = "MyEventSource")] |
| 15 | + [Guid("971d5f08-f366-421c-a25c-3aed379d5eb2")] |
| 16 | + class MyEventSource : PostSharpEventSource |
| 17 | + { |
| 18 | + private const string format = "{0} | {1} | {2} | {3}"; |
| 19 | + private const string invalidOperationExceptionMessage = "Use the Log method. This method is metadata-only."; |
| 20 | + private const byte version = 2; |
| 21 | + |
| 22 | + [Event(EventIds.MethodEntry, Level = EventLevel.Verbose, Message = format, Opcode = EventOpcode.Start, Version = version, Task = Tasks.Method)] |
| 23 | + internal void MethodEntry(string role, string type, string context, string message, int indentLevel) |
| 24 | + { |
| 25 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + [Event(EventIds.MethodSuccess, Level = EventLevel.Verbose, Message = format, Opcode = EventOpcode.Stop, Version = version, Task = Tasks.Method)] |
| 31 | + internal void MethodSuccess(string role, string type, string context, string message, int indentLevel) |
| 32 | + { |
| 33 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 34 | + } |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + [Event(EventIds.MethodException, Level = EventLevel.Warning, Message = format, Opcode = EventOpcode.Stop, Version = version, Task = Tasks.Method)] |
| 39 | + internal void MethodException(string role, string type, string context, string message, int indentLevel) |
| 40 | + { |
| 41 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + [Event(EventIds.MethodOvertime, Level = EventLevel.Warning, Message = format, Opcode = EventOpcode.Stop, Version = version, Task = Tasks.Method)] |
| 47 | + internal void MethodOvertime(string role, string type, string context, string message, int indentLevel) |
| 48 | + { |
| 49 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 50 | + } |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + [Event(EventIds.AsyncMethodAwait, Level = EventLevel.Verbose, Message = format, Opcode = EventOpcode.Suspend, Version = version, Task = Tasks.Method)] |
| 55 | + internal void AsyncMethodAwait(string role, string type, string context, string message, int indentLevel) |
| 56 | + { |
| 57 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + [Event(EventIds.AsyncMethodResume, Level = EventLevel.Verbose, Message = format, Opcode = EventOpcode.Resume, Version = version, Task = Tasks.Method)] |
| 63 | + internal void AsyncMethodResume(string role, string type, string context, string message, int indentLevel) |
| 64 | + { |
| 65 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + [Event(EventIds.ValueChanged, Level = EventLevel.Verbose, Message = format, Opcode = EventOpcode.Info, Version = version, Task = Tasks.Message)] |
| 71 | + internal void ValueChanged(string role, string type, string context, string message, int indentLevel) |
| 72 | + { |
| 73 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + [Event(EventIds.CustomVerbose, Level = EventLevel.Verbose, Message = format, Opcode = EventOpcode.Info, Version = version, Task = Tasks.Message)] |
| 79 | + internal void CustomVerbose(string role, string type, string context, string message, int indentLevel) |
| 80 | + { |
| 81 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 82 | + } |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + [Event(EventIds.CustomInfo, Level = EventLevel.Informational, Message = format, Opcode = EventOpcode.Info, Version = version, Task = Tasks.Message)] |
| 87 | + internal void CustomInfo(string role, string type, string context, string message, int indentLevel) |
| 88 | + { |
| 89 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 90 | + } |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + [Event(EventIds.CustomWarning, Level = EventLevel.Warning, Message = format, Opcode = EventOpcode.Info, Version = version, Task = Tasks.Message)] |
| 95 | + internal void CustomWarning(string role, string type, string context, string message, int indentLevel) |
| 96 | + { |
| 97 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + [Event(EventIds.CustomError, Level = EventLevel.Error, Message = format, Opcode = EventOpcode.Info, Version = version, Task = Tasks.Message)] |
| 103 | + internal void CustomError(string role, string type, string context, string message, int indentLevel) |
| 104 | + { |
| 105 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 106 | + } |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + [Event(EventIds.CustomCritical, Level = EventLevel.Critical, Message = format, Opcode = EventOpcode.Info, Version = version, Task = Tasks.Message)] |
| 111 | + internal void CustomCritical(string role, string type, string context, string message, int indentLevel) |
| 112 | + { |
| 113 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 114 | + } |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + [Event(EventIds.CustomActivityEntry, Level = EventLevel.Verbose, Message = format, Opcode = EventOpcode.Start, Version = version, Task = Tasks.CustomActivity)] |
| 119 | + internal void CustomActivityEntry(string role, string type, string context, string message, int indentLevel) |
| 120 | + { |
| 121 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + [Event(EventIds.CustomActivityException, Level = EventLevel.Warning, Message = format, Opcode = EventOpcode.Stop, Version = version, Task = Tasks.CustomActivity)] |
| 127 | + internal void CustomActivityException(string role, string type, string context, string message, int indentLevel) |
| 128 | + { |
| 129 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 130 | + } |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + [Event(EventIds.CustomActivitySuccess, Level = EventLevel.Verbose, Message = format, Opcode = EventOpcode.Stop, Version = version, Task = Tasks.CustomActivity)] |
| 135 | + internal void CustomActivitySuccess(string role, string type, string context, string message, int indentLevel) |
| 136 | + { |
| 137 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 138 | + } |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | + [Event(EventIds.CustomActivityFailure, Level = EventLevel.Warning, Message = format, Opcode = EventOpcode.Stop, Version = version, Task = Tasks.CustomActivity)] |
| 143 | + internal void CustomActivityFailure(string role, string type, string context, string message, int indentLevel) |
| 144 | + { |
| 145 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 146 | + } |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | + [Event(EventIds.IteratorYield, Level = EventLevel.Verbose, Message = format, Opcode = EventOpcode.Stop, Version = version, Task = Tasks.Method)] |
| 151 | + internal void IteratorYield(string role, string type, string context, string message, int indentLevel) |
| 152 | + { |
| 153 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 154 | + } |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | + [Event(EventIds.IteratorMoveNext, Level = EventLevel.Verbose, Message = format, Opcode = EventOpcode.Start, Version = version, Task = Tasks.Method)] |
| 159 | + internal void IteratorMoveNext(string role, string type, string context, string message, int indentLevel) |
| 160 | + { |
| 161 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 162 | + } |
| 163 | + |
| 164 | + |
| 165 | + |
| 166 | + [Event(EventIds.ExecutionPoint, Level = EventLevel.Verbose, Message = format, Opcode = EventOpcode.Info, Version = version, Task = Tasks.Method)] |
| 167 | + internal void ExecutionPoint(string role, string type, string context, string message, int indentLevel) |
| 168 | + { |
| 169 | + throw new InvalidOperationException(invalidOperationExceptionMessage); |
| 170 | + } |
| 171 | + |
| 172 | + } |
| 173 | +} |
0 commit comments