DiagnosticSource
An abstract class that allows code to be instrumented for production-time logging of rich data payloads for consumption within the process that was instrumented.
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace System.Diagnostics
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public abstract class DiagnosticSource
{
[RequiresUnreferencedCode("The type of object being written to DiagnosticSource cannot be discovered statically.")]
public abstract void Write(string name, [System.Runtime.CompilerServices.Nullable(2)] object value);
[RequiresUnreferencedCode("Only the properties of the T type will be preserved. Properties of referenced types and properties of derived types may be trimmed.")]
public void Write<[System.Runtime.CompilerServices.Nullable(2)] [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string name, T value)
{
Write(name, (object)value);
}
public abstract bool IsEnabled(string name);
[System.Runtime.CompilerServices.NullableContext(2)]
public virtual bool IsEnabled([System.Runtime.CompilerServices.Nullable(1)] string name, object arg1, object arg2 = null)
{
return IsEnabled(name);
}
[RequiresUnreferencedCode("The type of object being written to DiagnosticSource cannot be discovered statically.")]
public Activity StartActivity(Activity activity, [System.Runtime.CompilerServices.Nullable(2)] object args)
{
activity.Start();
Write(activity.OperationName + ".Start", args);
return activity;
}
[RequiresUnreferencedCode("Only the properties of the T type will be preserved. Properties of referenced types and properties of derived types may be trimmed.")]
public Activity StartActivity<[System.Runtime.CompilerServices.Nullable(2)] [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(Activity activity, T args)
{
return StartActivity(activity, (object)args);
}
[RequiresUnreferencedCode("The type of object being written to DiagnosticSource cannot be discovered statically.")]
public void StopActivity(Activity activity, [System.Runtime.CompilerServices.Nullable(2)] object args)
{
if (activity.Duration == TimeSpan.Zero)
activity.SetEndTime(Activity.GetUtcNow());
Write(activity.OperationName + ".Stop", args);
activity.Stop();
}
[RequiresUnreferencedCode("Only the properties of the T type will be preserved. Properties of referenced types and properties of derived types may be trimmed.")]
public void StopActivity<[System.Runtime.CompilerServices.Nullable(2)] [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(Activity activity, T args)
{
StopActivity(activity, (object)args);
}
public virtual void OnActivityImport(Activity activity, [System.Runtime.CompilerServices.Nullable(2)] object payload)
{
}
public virtual void OnActivityExport(Activity activity, [System.Runtime.CompilerServices.Nullable(2)] object payload)
{
}
}
}