<PackageReference Include="System.ClientModel" Version="1.7.0" />

ClientModelEventSource

using System.ClientModel.Primitives; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using System.Runtime.CompilerServices; using System.Text; namespace System.ClientModel.Internal { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] [EventSource(Name = "System.ClientModel")] internal sealed class ClientModelEventSource : EventSource { public static ClientModelEventSource Log = new ClientModelEventSource("System.ClientModel", null); private ClientModelEventSource(string eventSourceName, [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] string[] traits = null) : base(eventSourceName, EventSourceSettings.Default, traits) { } [NonEvent] public void Request(string requestId, PipelineRequest request, [System.Runtime.CompilerServices.Nullable(2)] string clientAssembly, PipelineMessageSanitizer sanitizer) { if (IsEnabled(EventLevel.Informational, EventKeywords.None)) Request(requestId, request.Method, sanitizer.SanitizeUrl(request.Uri.AbsoluteUri), FormatHeaders(request.Headers, sanitizer), clientAssembly); } [Event(1, Level = EventLevel.Informational, Message = "Request [{0}] {1} {2}\r\n{3}client assembly: {4}")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with primitive types.")] private void Request([System.Runtime.CompilerServices.Nullable(2)] string requestId, string method, string uri, string headers, [System.Runtime.CompilerServices.Nullable(2)] string clientAssembly) { WriteEvent(1, new object[5] { requestId, method, uri, headers, clientAssembly }); } [NonEvent] public void RequestContent(string requestId, byte[] content, [System.Runtime.CompilerServices.Nullable(2)] Encoding textEncoding) { if (IsEnabled(EventLevel.Verbose, EventKeywords.None)) { if (textEncoding != null) RequestContentText(requestId, textEncoding.GetString(content)); else RequestContent(requestId, content); } } [Event(2, Level = EventLevel.Verbose, Message = "Request [{0}] content: {1}")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with an array with primitive type elements.")] private void RequestContent([System.Runtime.CompilerServices.Nullable(2)] string requestId, byte[] content) { WriteEvent(2, new object[2] { requestId, content }); } [Event(17, Level = EventLevel.Verbose, Message = "Request [{0}] content: {1}")] private void RequestContentText([System.Runtime.CompilerServices.Nullable(2)] string requestId, string content) { WriteEvent(17, requestId, content); } [NonEvent] public void Response(string requestId, PipelineResponse response, double seconds, PipelineMessageSanitizer sanitizer) { if (IsEnabled(EventLevel.Informational, EventKeywords.None)) Response(requestId, response.Status, response.ReasonPhrase, FormatHeaders(response.Headers, sanitizer), seconds); } [Event(5, Level = EventLevel.Informational, Message = "Response [{0}] {1} {2} ({4:00.0}s)\r\n{3}")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with primitive types.")] private void Response([System.Runtime.CompilerServices.Nullable(2)] string requestId, int status, string reasonPhrase, string headers, double seconds) { WriteEvent(5, new object[5] { requestId, status, reasonPhrase, headers, seconds }); } [NonEvent] public void ResponseContent(string requestId, byte[] content, [System.Runtime.CompilerServices.Nullable(2)] Encoding textEncoding) { if (IsEnabled(EventLevel.Verbose, EventKeywords.None)) { if (textEncoding != null) ResponseContentText(requestId, textEncoding.GetString(content)); else ResponseContent(requestId, content); } } [Event(6, Level = EventLevel.Verbose, Message = "Response [{0}] content: {1}")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with an array with primitive type elements.")] private void ResponseContent([System.Runtime.CompilerServices.Nullable(2)] string requestId, byte[] content) { WriteEvent(6, new object[2] { requestId, content }); } [Event(13, Level = EventLevel.Verbose, Message = "Response [{0}] content: {1}")] private void ResponseContentText([System.Runtime.CompilerServices.Nullable(2)] string requestId, string content) { WriteEvent(13, requestId, content); } [NonEvent] public void ResponseContentBlock(string requestId, int blockNumber, byte[] content, [System.Runtime.CompilerServices.Nullable(2)] Encoding textEncoding) { if (IsEnabled(EventLevel.Verbose, EventKeywords.None)) { if (textEncoding != null) ResponseContentTextBlock(requestId, blockNumber, textEncoding.GetString(content)); else ResponseContentBlock(requestId, blockNumber, content); } } [Event(11, Level = EventLevel.Verbose, Message = "Response [{0}] content block {1}: {2}")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with an array with primitive type elements.")] private void ResponseContentBlock([System.Runtime.CompilerServices.Nullable(2)] string requestId, int blockNumber, byte[] content) { WriteEvent(11, new object[3] { requestId, blockNumber, content }); } [Event(15, Level = EventLevel.Verbose, Message = "Response [{0}] content block {1}: {2}")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with primitive types.")] private void ResponseContentTextBlock([System.Runtime.CompilerServices.Nullable(2)] string requestId, int blockNumber, string content) { WriteEvent(15, new object[3] { requestId, blockNumber, content }); } [NonEvent] public void ErrorResponse(string requestId, PipelineResponse response, double elapsed, PipelineMessageSanitizer sanitizer) { if (IsEnabled(EventLevel.Warning, EventKeywords.None)) ErrorResponse(requestId, response.Status, response.ReasonPhrase, FormatHeaders(response.Headers, sanitizer), elapsed); } [Event(8, Level = EventLevel.Warning, Message = "Error response [{0}] {1} {2} ({4:00.0}s)\r\n{3}")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with primitive types.")] private void ErrorResponse([System.Runtime.CompilerServices.Nullable(2)] string requestId, int status, string reasonPhrase, string headers, double seconds) { WriteEvent(8, new object[5] { requestId, status, reasonPhrase, headers, seconds }); } [NonEvent] public void ErrorResponseContent(string requestId, byte[] content, [System.Runtime.CompilerServices.Nullable(2)] Encoding textEncoding) { if (IsEnabled(EventLevel.Informational, EventKeywords.None)) { if (textEncoding != null) ErrorResponseContentText(requestId, textEncoding.GetString(content)); else ErrorResponseContent(requestId, content); } } [Event(9, Level = EventLevel.Informational, Message = "Error response [{0}] content: {1}")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with an array with primitive type elements.")] private void ErrorResponseContent([System.Runtime.CompilerServices.Nullable(2)] string requestId, byte[] content) { WriteEvent(9, new object[2] { requestId, content }); } [Event(14, Level = EventLevel.Informational, Message = "Error response [{0}] content: {1}")] private void ErrorResponseContentText([System.Runtime.CompilerServices.Nullable(2)] string requestId, string content) { WriteEvent(14, requestId, content); } [NonEvent] public void ErrorResponseContentBlock(string requestId, int blockNumber, byte[] content, [System.Runtime.CompilerServices.Nullable(2)] Encoding textEncoding) { if (IsEnabled(EventLevel.Informational, EventKeywords.None)) { if (textEncoding != null) ErrorResponseContentTextBlock(requestId, blockNumber, textEncoding.GetString(content)); else ErrorResponseContentBlock(requestId, blockNumber, content); } } [Event(12, Level = EventLevel.Informational, Message = "Error response [{0}] content block {1}: {2}")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with an array with primitive type elements.")] private void ErrorResponseContentBlock([System.Runtime.CompilerServices.Nullable(2)] string requestId, int blockNumber, byte[] content) { WriteEvent(12, new object[3] { requestId, blockNumber, content }); } [Event(16, Level = EventLevel.Informational, Message = "Error response [{0}] content block {1}: {2}")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with primitive types.")] private void ErrorResponseContentTextBlock([System.Runtime.CompilerServices.Nullable(2)] string requestId, int blockNumber, string content) { WriteEvent(16, new object[3] { requestId, blockNumber, content }); } [System.Runtime.CompilerServices.NullableContext(2)] [Event(10, Level = EventLevel.Informational, Message = "Request [{0}] attempt number {1} took {2:00.0}s")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with primitive types.")] public void RequestRetrying(string requestId, int retryNumber, double seconds) { if (IsEnabled(EventLevel.Informational, EventKeywords.None)) WriteEvent(10, new object[3] { requestId, retryNumber, seconds }); } [System.Runtime.CompilerServices.NullableContext(2)] [Event(7, Level = EventLevel.Warning, Message = "Response [{0}] took {1:00.0}s")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with primitive types.")] public void ResponseDelay(string requestId, double seconds) { if (IsEnabled(EventLevel.Warning, EventKeywords.None)) WriteEvent(7, new object[2] { requestId, seconds }); } [Event(18, Level = EventLevel.Informational, Message = "Request [{0}] exception {1}")] public void ExceptionResponse([System.Runtime.CompilerServices.Nullable(2)] string requestId, string exception) { if (IsEnabled(EventLevel.Informational, EventKeywords.None)) WriteEvent(18, requestId, exception); } [NonEvent] private string FormatHeaders([System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0, 1, 1 })] IEnumerable<KeyValuePair<string, string>> headers, PipelineMessageSanitizer sanitizer) { StringBuilder stringBuilder = new StringBuilder(); foreach (KeyValuePair<string, string> header in headers) { stringBuilder.Append(header.Key); stringBuilder.Append(':'); stringBuilder.Append(sanitizer.SanitizeHeader(header.Key, header.Value)); stringBuilder.Append(Environment.NewLine); } return stringBuilder.ToString(); } } }