Skip to content

Commit 6ae170c

Browse files
authored
logging error code as part of eventId for diagnostic events (#9643)
1 parent b0db13b commit 6ae170c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/WebJobs.Script.WebHost/Diagnostics/SystemLogger.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
6969
string stateFunctionName = null;
7070
string stateEventName = null;
7171
string stateActivityId = null;
72+
string diagnosticEventErrorCode = null;
73+
bool isDiagnosticEvent = false;
7274
if (state is IEnumerable<KeyValuePair<string, object>> stateProps)
7375
{
7476
foreach (var kvp in stateProps)
@@ -77,6 +79,14 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
7779
{
7880
stateSourceValue = kvp.Value?.ToString();
7981
}
82+
else if (string.Equals(kvp.Key, ScriptConstants.DiagnosticEventKey, StringComparison.OrdinalIgnoreCase))
83+
{
84+
isDiagnosticEvent = true;
85+
}
86+
else if (string.Equals(kvp.Key, ScriptConstants.ErrorCodeKey, StringComparison.OrdinalIgnoreCase))
87+
{
88+
diagnosticEventErrorCode = kvp.Value?.ToString();
89+
}
8090
else if (string.Equals(kvp.Key, ScriptConstants.LogPropertyIsUserLogKey, StringComparison.OrdinalIgnoreCase))
8191
{
8292
if ((bool)kvp.Value)
@@ -147,6 +157,8 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
147157
// otherwise the ETW event will fail to be persisted (silently)
148158
string summary = formattedMessage ?? string.Empty;
149159
string eventName = !string.IsNullOrEmpty(eventId.Name) ? eventId.Name : stateEventName ?? string.Empty;
160+
eventName = isDiagnosticEvent ? $"DiagnosticEvent-{diagnosticEventErrorCode}" : eventName;
161+
150162
string activityId = stateActivityId ?? scopeActivityId ?? string.Empty;
151163
var options = _appServiceOptions;
152164
string subscriptionId = options.SubscriptionId ?? string.Empty;

0 commit comments

Comments
 (0)