Table of Contents

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

The Key used when applying insights to the Data dictionary.

public const string Key = "$(___exceptionInsights___)"

Field Value

string

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

exception T

The exception to enrich.

runtimeParameters object[]

The runtime parameters of the method that threw the exception.

snapshots SystemSnapshots

A bitwise combination of the enumeration values that specify which areas of a system to capture.

Returns

T

The provided exception enriched with an embedded entry of insights.

Type Parameters

T

The 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

exception T

The exception to enrich.

thrower MethodBase

The method that threw the exception.

runtimeParameters object[]

The optional runtime parameters of the thrower.

snapshots SystemSnapshots

A bitwise combination of the enumeration values that specify which areas of a system to capture.

Returns

T

The provided exception enriched with an embedded entry of insights.

Type Parameters

T

The type of the exception.