Class ExceptionInsights
- Namespace
- Cuemon
- Assembly
- Cuemon.Core.dll
Provides a set of static methods for embedding environment specific insights to an exception.
public static class ExceptionInsights
- Inheritance
-
ExceptionInsights
Examples
The following example shows how to enrich an exception with thread and environment information using ExceptionInsights.Embed. It catches an exception, embeds runtime parameters and system snapshots, then checks for the embedded insight data in the exception's Data dictionary.
using System;
using System.Reflection;
namespace Cuemon;
public class ExceptionInsightsExample
{
public void Demonstrate()
{
try
{
throw new InvalidOperationException("Something went wrong.");
}
catch (InvalidOperationException ex)
{
// Enrich the exception with thread and environment information
ExceptionInsights.Embed(ex,
runtimeParameters: new object[] { "param1", 42 },
snapshots: SystemSnapshots.CaptureThreadInfo | SystemSnapshots.CaptureEnvironmentInfo);
// The enriched exception now has embedded insight data in its Data dictionary
Console.WriteLine(ex.Data.Contains(ExceptionInsights.Key)
? "Insights embedded successfully."
: "No insights available.");
}
}
}
Fields
Key
public const string Key = "$(___exceptionInsights___)"
Field Value
Methods
Embed<T>(T, object[], SystemSnapshots)
Enriches and embed insights about an Exception.
public static T Embed<T>(T exception, object[] runtimeParameters = null, SystemSnapshots snapshots = SystemSnapshots.None) where T : Exception
Parameters
exceptionTThe exception to enrich.
runtimeParametersobject[]The runtime parameters of the method that threw the
exception.snapshotsSystemSnapshotsA bitwise combination of the enumeration values that specify which areas of a system to capture.
Returns
- T
The provided
exceptionenriched with an embedded entry of insights.
Type Parameters
TThe type of the
exception.
Embed<T>(T, MethodBase, object[], SystemSnapshots)
Enriches and embed insights about an Exception.
public static T Embed<T>(T exception, MethodBase thrower, object[] runtimeParameters = null, SystemSnapshots snapshots = SystemSnapshots.None) where T : Exception
Parameters
exceptionTThe exception to enrich.
throwerMethodBaseThe method that threw the
exception.runtimeParametersobject[]The optional runtime parameters of the
thrower.snapshotsSystemSnapshotsA bitwise combination of the enumeration values that specify which areas of a system to capture.
Returns
- T
The provided
exceptionenriched with an embedded entry of insights.
Type Parameters
TThe type of the
exception.