forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseAbstractEventSource.cs
More file actions
88 lines (76 loc) · 2.69 KB
/
UseAbstractEventSource.cs
File metadata and controls
88 lines (76 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
#if USE_MDT_EVENTSOURCE
using Microsoft.Diagnostics.Tracing;
#else
using System.Diagnostics.Tracing;
#endif
// We wish to test both Microsoft.Diagnostics.Tracing (Nuget)
// and System.Diagnostics.Tracing (Framework), we use this Ifdef make each kind
namespace SdtEventSources
{
public abstract class UtilBaseEventSource : EventSource
{
protected UtilBaseEventSource()
: base()
{ }
protected UtilBaseEventSource(bool throwOnEventWriteErrors)
: base(throwOnEventWriteErrors)
{ }
protected unsafe void WriteEvent(int eventId, int arg1, short arg2, long arg3)
{
if (IsEnabled())
{
EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
descrs[0].DataPointer = (IntPtr)(&arg1);
descrs[0].Size = 4;
descrs[1].DataPointer = (IntPtr)(&arg2);
descrs[1].Size = 2;
descrs[2].DataPointer = (IntPtr)(&arg3);
descrs[2].Size = 8;
WriteEventCore(eventId, 3, descrs);
}
}
}
[EventSource(Name = "OptimizedEventSource")]
public sealed class OptimizedEventSource : UtilBaseEventSource
{
public static OptimizedEventSource Log = new OptimizedEventSource();
public OptimizedEventSource()
: base(true)
{ }
[Event(1,
Channel = EventChannel.Admin,
Keywords = Keywords.Kwd1, Level = EventLevel.Informational, Message = "WriteIntToAdmin called with argument {0}")]
public void WriteToAdmin(int n, short sh, long l)
{
if (IsEnabled(EventLevel.Informational, Keywords.Kwd1
, EventChannel.Admin
))
WriteEvent(1, n, sh, l);
}
#region Keywords / Tasks /Opcodes / Channels
/// <summary>
/// The keyword definitions for the ETW manifest.
/// </summary>
public static class Keywords
{
public const EventKeywords Kwd1 = (EventKeywords)1;
public const EventKeywords Kwd2 = (EventKeywords)2;
}
/// <summary>
/// The task definitions for the ETW manifest.
/// </summary>
public static class Tasks
{
public const EventTask Http = (EventTask)1;
}
public static class Opcodes
{
public const EventOpcode Delete = (EventOpcode)100;
}
#endregion
}
}