irontelemetry-dotnet/Models.cs

69 lines
1.5 KiB
C#

namespace IronTelemetry.Client;
/// <summary>
/// Telemetry level for messages.
/// </summary>
public enum TelemetryLevel
{
Debug,
Info,
Warning,
Error,
Fatal
}
/// <summary>
/// Breadcrumb level.
/// </summary>
public enum BreadcrumbLevel
{
Debug,
Info,
Warning,
Error
}
/// <summary>
/// A breadcrumb represents an event that happened before an error.
/// </summary>
public class Breadcrumb
{
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
public string Category { get; set; } = "default";
public string Message { get; set; } = string.Empty;
public BreadcrumbLevel Level { get; set; } = BreadcrumbLevel.Info;
public Dictionary<string, object>? Data { get; set; }
}
/// <summary>
/// Additional context for exception capture.
/// </summary>
public class ExceptionContext
{
public string? UserId { get; set; }
public string? UserEmail { get; set; }
public string? TraceId { get; set; }
public string? SpanId { get; set; }
public Dictionary<string, object> Extras { get; set; } = new();
public ExceptionContext WithUser(string? id, string? email = null)
{
UserId = id;
UserEmail = email;
return this;
}
public ExceptionContext WithTrace(string traceId, string? spanId = null)
{
TraceId = traceId;
SpanId = spanId;
return this;
}
public ExceptionContext WithExtra(string key, object value)
{
Extras[key] = value;
return this;
}
}