From 408aaf09accf61b8ffe6d5dee5e768f5b9b6245a Mon Sep 17 00:00:00 2001 From: Vance Morrison Date: Mon, 26 Sep 2016 11:49:28 -0700 Subject: [PATCH] Add the serialization of the Message field when writting LTTng events on Linux. --- .../src/System/Diagnostics/Eventing/EventSource.cs | 2 +- .../System/Diagnostics/Eventing/XplatEventLogger.cs | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs b/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs index 8c2edfd..81683a7 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs @@ -4927,7 +4927,7 @@ namespace System.Diagnostics.Tracing } /// - /// Gets the message for the event. + /// Gets the message for the event. If the message has {N} parameters they are NOT substituted. /// public string Message { diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/XplatEventLogger.cs b/src/mscorlib/src/System/Diagnostics/Eventing/XplatEventLogger.cs index d7112fc..5fddc77 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/XplatEventLogger.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/XplatEventLogger.cs @@ -73,9 +73,8 @@ namespace System.Diagnostics.Tracing } } - private static string Serialize(ReadOnlyCollection payloadName, ReadOnlyCollection payload, string sep = ", ") + private static string Serialize(ReadOnlyCollection payloadName, ReadOnlyCollection payload, string eventMessage) { - if (payloadName == null || payload == null ) return String.Empty; @@ -92,6 +91,16 @@ namespace System.Diagnostics.Tracing var sb = StringBuilderCache.Acquire(); sb.Append('{'); + + // If the event has a message, send that as well as a pseudo-field + if (!string.IsNullOrEmpty(eventMessage)) + { + sb.Append("\\\"EventSource_Message\\\":\\\""); + minimalJsonserializer(eventMessage,sb); + sb.Append("\\\""); + sb.Append(", "); + } + for (int i = 0; i < eventDataCount; i++) { var fieldstr = payloadName[i].ToString(); @@ -114,8 +123,7 @@ namespace System.Diagnostics.Tracing sb.Append(payload[i].ToString()); } - sb.Append(sep); - + sb.Append(", "); } sb.Length -= sep.Length; @@ -149,7 +157,7 @@ namespace System.Diagnostics.Tracing if (eventData.Payload != null) { try{ - payload = Serialize(eventData.PayloadNames, eventData.Payload); + payload = Serialize(eventData.PayloadNames, eventData.Payload, eventData.Message); } catch (Exception ex) { -- 2.7.4