Closed chenxinyanc closed 1 year ago
Tagging subscribers to this area: @tommcdon See info in area-owners.md if you want to be subscribed.
Author: | chenxinyanc |
---|---|
Assignees: | - |
Labels: | `area-Diagnostics-coreclr`, `untriaged` |
Milestone: | - |
This method is not meant to be called by non-.NET Runtime code.
Have you looked into registering your own TraceListener
? It should allow you to do what you are looking for.
TraceListener.Fail
to log your telemetryTraceListener
by calling System.Diagnostics.Trace.Listeners.Clear();
as the very first thing)Thans for pointing that out! I've neglected there is a SetDebugProvider
call when I access the Trace.Listeners
collection.
Then I suppose I'll implement a custom trace listener that
Debugger.Log
to write messages to debugger in Write
implementation, andFail
implementation.
We're working on an ASP.NET 6 application running on a certain cluster. Sometimes in our debugging process, we'd like to deploy the application in DEBUG profile to our dev cluster and try it out. We send HTTP requests and check out the telemetry sent from the application.
We have a lot of
Debug.Assert
calls in our app. If there is any assertion failure,Environment.FailFast
will eventually get invoked, emitting the stack trace in Console and in Windows Application event logs.This poses some inconvenience for us, and we are looking for some solution so that we can figure out what has happend without RDP to the VMSS or relaying the event logs. I found that
Environment.FailFast
is invoked fromDebugProvider
. After taking a look at the following function, I think I can just replace the currentDebugProvider
so that it can emit some telemetry, (synchronously) flush it, before eventually failfast.https://github.com/dotnet/runtime/blob/967250cc86b4c613015066b47b882e7424fdb590/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Debug.cs#L18-L27
However, while
Debug.SetProvider
is a public method inSystem.Private.CoreLib
, this method is not forwarded toSystem.Runtime
ref assembly.Thus I'm not sure
DebugProvider
and to accessDebug.SetProvider
without reflection / emit,