forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPSEtwLog.cs
More file actions
316 lines (286 loc) · 12.7 KB
/
Copy pathPSEtwLog.cs
File metadata and controls
316 lines (286 loc) · 12.7 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#if !UNIX
//
// Copyright (C) Microsoft. All rights reserved.
//
using System.Globalization;
using System.Management.Automation.Internal;
using System.Collections.Generic;
namespace System.Management.Automation.Tracing
{
/// <summary>
/// ETW logging API
/// </summary>
internal static class PSEtwLog
{
private static PSEtwLogProvider provider;
/// <summary>
/// Class constructor
/// </summary>
static PSEtwLog()
{
provider = new PSEtwLogProvider();
}
/// <summary>
/// Provider interface function for logging health event
/// </summary>
/// <param name="logContext"></param>
/// <param name="eventId"></param>
/// <param name="exception"></param>
/// <param name="additionalInfo"></param>
///
internal static void LogEngineHealthEvent(LogContext logContext, int eventId, Exception exception, Dictionary<String, String> additionalInfo)
{
provider.LogEngineHealthEvent(logContext, eventId, exception, additionalInfo);
}
/// <summary>
/// Provider interface function for logging engine lifecycle event
/// </summary>
/// <param name="logContext"></param>
/// <param name="newState"></param>
/// <param name="previousState"></param>
///
internal static void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
{
provider.LogEngineLifecycleEvent(logContext, newState, previousState);
}
/// <summary>
/// Provider interface function for logging command health event
/// </summary>
/// <param name="logContext"></param>
/// <param name="exception"></param>
internal static void LogCommandHealthEvent(LogContext logContext, Exception exception)
{
provider.LogCommandHealthEvent(logContext, exception);
}
/// <summary>
/// Provider interface function for logging command lifecycle event
/// </summary>
/// <param name="logContext"></param>
/// <param name="newState"></param>
///
internal static void LogCommandLifecycleEvent(LogContext logContext, CommandState newState)
{
provider.LogCommandLifecycleEvent(() => logContext, newState);
}
/// <summary>
/// Provider interface function for logging pipeline execution detail.
/// </summary>
/// <param name="logContext"></param>
/// <param name="pipelineExecutionDetail"></param>
internal static void LogPipelineExecutionDetailEvent(LogContext logContext, List<String> pipelineExecutionDetail)
{
provider.LogPipelineExecutionDetailEvent(logContext, pipelineExecutionDetail);
}
/// <summary>
/// Provider interface function for logging provider health event
/// </summary>
/// <param name="logContext"></param>
/// <param name="providerName"></param>
/// <param name="exception"></param>
internal static void LogProviderHealthEvent(LogContext logContext, string providerName, Exception exception)
{
provider.LogProviderHealthEvent(logContext, providerName, exception);
}
/// <summary>
/// Provider interface function for logging provider lifecycle event
/// </summary>
/// <param name="logContext"></param>
/// <param name="providerName"></param>
/// <param name="newState"></param>
///
internal static void LogProviderLifecycleEvent(LogContext logContext, string providerName, ProviderState newState)
{
provider.LogProviderLifecycleEvent(logContext, providerName, newState);
}
/// <summary>
/// Provider interface function for logging settings event
/// </summary>
/// <param name="logContext"></param>
/// <param name="variableName"></param>
/// <param name="value"></param>
/// <param name="previousValue"></param>
///
internal static void LogSettingsEvent(LogContext logContext, string variableName, string value, string previousValue)
{
provider.LogSettingsEvent(logContext, variableName, value, previousValue);
}
/// <summary>
/// Logs information to the operational channel
/// </summary>
/// <param name="id"></param>
/// <param name="opcode"></param>
/// <param name="task"></param>
/// <param name="keyword"></param>
/// <param name="args"></param>
internal static void LogOperationalInformation(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args)
{
provider.WriteEvent(id, PSChannel.Operational, opcode, PSLevel.Informational, task, keyword, args);
}
/// <summary>
/// Logs information to the operational channel
/// </summary>
/// <param name="id"></param>
/// <param name="opcode"></param>
/// <param name="task"></param>
/// <param name="keyword"></param>
/// <param name="args"></param>
internal static void LogOperationalWarning(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args)
{
provider.WriteEvent(id, PSChannel.Operational, opcode, PSLevel.Warning, task, keyword, args);
}
/// <summary>
/// Logs Verbose to the operational channel
/// </summary>
/// <param name="id"></param>
/// <param name="opcode"></param>
/// <param name="task"></param>
/// <param name="keyword"></param>
/// <param name="args"></param>
internal static void LogOperationalVerbose(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args)
{
provider.WriteEvent(id, PSChannel.Operational, opcode, PSLevel.Verbose, task, keyword, args);
}
/// <summary>
/// Logs error message to the analytic channel
/// </summary>
/// <param name="id"></param>
/// <param name="opcode"></param>
/// <param name="task"></param>
/// <param name="keyword"></param>
/// <param name="args"></param>
internal static void LogAnalyticError(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args)
{
provider.WriteEvent(id, PSChannel.Analytic, opcode, PSLevel.Error, task, keyword, args);
}
/// <summary>
/// Logs warning message to the analytic channel
/// </summary>
/// <param name="id"></param>
/// <param name="opcode"></param>
/// <param name="task"></param>
/// <param name="keyword"></param>
/// <param name="args"></param>
internal static void LogAnalyticWarning(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args)
{
provider.WriteEvent(id, PSChannel.Analytic, opcode, PSLevel.Warning, task, keyword, args);
}
/// <summary>
/// Logs remoting fragment data to verbose channel.
/// </summary>
/// <param name="id"></param>
/// <param name="opcode"></param>
/// <param name="task"></param>
/// <param name="keyword"></param>
/// <param name="objectId"></param>
/// <param name="fragmentId"></param>
/// <param name="isStartFragment"></param>
/// <param name="isEndFragment"></param>
/// <param name="fragmentLength"></param>
/// <param name="fragmentData"></param>
internal static void LogAnalyticVerbose(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword,
Int64 objectId,
Int64 fragmentId,
int isStartFragment,
int isEndFragment,
UInt32 fragmentLength,
PSETWBinaryBlob fragmentData)
{
if (provider.IsEnabled(PSLevel.Verbose, keyword))
{
string payLoadData = BitConverter.ToString(fragmentData.blob, fragmentData.offset, fragmentData.length);
payLoadData = string.Format(CultureInfo.InvariantCulture, "0x{0}", payLoadData.Replace("-", ""));
provider.WriteEvent(id, PSChannel.Analytic, opcode, PSLevel.Verbose, task, keyword,
objectId, fragmentId, isStartFragment, isEndFragment, fragmentLength,
payLoadData);
}
}
/// <summary>
/// Logs verbose message to the analytic channel
/// </summary>
/// <param name="id"></param>
/// <param name="opcode"></param>
/// <param name="task"></param>
/// <param name="keyword"></param>
/// <param name="args"></param>
internal static void LogAnalyticVerbose(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args)
{
provider.WriteEvent(id, PSChannel.Analytic, opcode, PSLevel.Verbose, task, keyword, args);
}
/// <summary>
/// Logs informational message to the analytic channel
/// </summary>
/// <param name="id"></param>
/// <param name="opcode"></param>
/// <param name="task"></param>
/// <param name="keyword"></param>
/// <param name="args"></param>
internal static void LogAnalyticInformational(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args)
{
provider.WriteEvent(id, PSChannel.Analytic, opcode, PSLevel.Informational, task, keyword, args);
}
/// <summary>
/// Logs error message to operation channel.
/// </summary>
/// <param name="id"></param>
/// <param name="opcode"></param>
/// <param name="task"></param>
/// <param name="keyword"></param>
/// <param name="args"></param>
internal static void LogOperationalError(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args)
{
provider.WriteEvent(id, PSChannel.Operational, opcode, PSLevel.Error, task, keyword, args);
}
/// <summary>
/// Logs error message to the operational channel
/// </summary>
/// <param name="id"></param>
/// <param name="opcode"></param>
/// <param name="task"></param>
/// <param name="logContext"></param>
/// <param name="payLoad"></param>
internal static void LogOperationalError(PSEventId id, PSOpcode opcode, PSTask task, LogContext logContext, string payLoad)
{
provider.WriteEvent(id, PSChannel.Operational, opcode, task, logContext, payLoad);
}
internal static void SetActivityIdForCurrentThread(Guid newActivityId)
{
provider.SetActivityIdForCurrentThread(newActivityId);
}
internal static void ReplaceActivityIdForCurrentThread(Guid newActivityId,
PSEventId eventForOperationalChannel, PSEventId eventForAnalyticChannel, PSKeyword keyword, PSTask task)
{
// set the new activity id
provider.SetActivityIdForCurrentThread(newActivityId);
// Once the activity id is set, write the transfer event
WriteTransferEvent(newActivityId, eventForOperationalChannel, eventForAnalyticChannel, keyword, task);
}
/// <summary>
/// Writes a transfer event mapping current activity id
/// with a related activity id
/// This function writes a transfer event for both the
/// operational and analytic channels
/// </summary>
/// <param name="relatedActivityId"></param>
/// <param name="eventForOperationalChannel"></param>
/// <param name="eventForAnalyticChannel"></param>
/// <param name="keyword"></param>
/// <param name="task"></param>
internal static void WriteTransferEvent(Guid relatedActivityId, PSEventId eventForOperationalChannel,
PSEventId eventForAnalyticChannel, PSKeyword keyword, PSTask task)
{
provider.WriteEvent(eventForOperationalChannel, PSChannel.Operational, PSOpcode.Method, PSLevel.Informational, task,
PSKeyword.UseAlwaysOperational);
provider.WriteEvent(eventForAnalyticChannel, PSChannel.Analytic, PSOpcode.Method, PSLevel.Informational, task,
PSKeyword.UseAlwaysAnalytic);
}
/// <summary>
/// Writes a transfer event
/// </summary>
/// <param name="parentActivityId"></param>
internal static void WriteTransferEvent(Guid parentActivityId)
{
provider.WriteTransferEvent(parentActivityId);
}
}
}
#endif