Capturing Logs

Capture application logs in Ansight session timelines and optionally surface Ansight SDK diagnostics.

Use the base Ansight package for lightweight runtime events in addition to metrics and FPS sampling.

Numeric telemetry such as FPS and memory is documented separately in Performance Telemetry.

Screen-view events are documented separately in Screen Views. Foreground and background tracking is documented separately in App Lifecycle.

Capture Your Own Runtime Log Events

If you want your application logs to appear inside Ansight session data, record them as events:

using Ansight;
using Ansight.Telemetry.Events;

Runtime.Event("Sync started", AppEventType.Info, "job=inventory");
Runtime.Event("Cache miss", AppEventType.Warning, "key=profile:42");
Runtime.Event("Checkout failed", AppEventType.Error, "httpStatus=500");

You can also attach a custom channel:

Runtime.Event("Worker retry", AppEventType.Warning, channel: 42, details: "attempt=2");

This is the primary way to make app-level logs and metadata part of the Ansight session timeline.

Receive Third-Party Logs In Ansight

If your goal is to get application logs into Ansight, invert the integration order:

  • do not forward Ansight SDK diagnostics into your logging framework and stop there
  • instead, attach an Ansight receiver, provider, sink, or wrapper to the logging framework you already use
  • emit Runtime.Event(...) entries from that integration point

That way the logs become part of the Ansight session timeline and are available for later analysis.

Microsoft.Extensions.Logging

Please use this skill /skills/dotnet/ansight-logging-microsoft-extensions-logging.md to integrate Ansight logging into Microsoft.Extensions.Logging.

Copyable prompt:

Please use this skill https://ansight.ai/skills/dotnet/ansight-logging-microsoft-extensions-logging.md to integrate Ansight logging into Microsoft.Extensions.Logging. Attach an Ansight logger provider to my existing logging pipeline, mirror application logs into Runtime.Event(...), preserve my current providers, and capture exception details in Ansight.
using Ansight;
using Ansight.Telemetry.Events;
using Microsoft.Extensions.Logging;

public sealed class AnsightLoggerProvider : ILoggerProvider
{
    public ILogger CreateLogger(string categoryName) => new AnsightLogger(categoryName);
    public void Dispose()
    {
    }
}

internal sealed class AnsightLogger : ILogger
{
    private readonly string categoryName;

    public AnsightLogger(string categoryName)
    {
        this.categoryName = categoryName;
    }

    public IDisposable BeginScope<TState>(TState state) where TState : notnull => NullScope.Instance;

    public bool IsEnabled(LogLevel logLevel) => logLevel != LogLevel.None;

    public void Log<TState>(
        LogLevel logLevel,
        EventId eventId,
        TState state,
        Exception? exception,
        Func<TState, Exception?, string> formatter)
    {
        var message = formatter(state, exception);
        var type = logLevel switch
        {
            LogLevel.Trace or LogLevel.Debug => AppEventType.Debug,
            LogLevel.Information => AppEventType.Info,
            LogLevel.Warning => AppEventType.Warning,
            LogLevel.Error or LogLevel.Critical => AppEventType.Error,
            _ => AppEventType.Event
        };

        Runtime.Event(message, type, $"category={categoryName};eventId={eventId.Id}");

        if (exception is not null)
        {
            Runtime.Event(exception.GetType().Name, AppEventType.Exception, exception.Message);
        }
    }

    private sealed class NullScope : IDisposable
    {
        public static NullScope Instance { get; } = new();

        public void Dispose()
        {
        }
    }
}

Register the provider alongside your existing logging setup:

builder.Logging.AddProvider(new AnsightLoggerProvider());

Serilog

Please use this skill /skills/dotnet/ansight-logging-serilog.md to integrate Ansight logging into Serilog.

Copyable prompt:

Please use this skill https://ansight.ai/skills/dotnet/ansight-logging-serilog.md to integrate Ansight logging into Serilog. Attach an Ansight sink to my existing Serilog pipeline, mirror application logs into Runtime.Event(...), preserve my current sinks and enrichers, and capture exception details in Ansight.
using Ansight;
using Ansight.Telemetry.Events;
using Serilog;
using Serilog.Core;
using Serilog.Events;

public sealed class AnsightSerilogSink : ILogEventSink
{
    public void Emit(LogEvent logEvent)
    {
        var type = logEvent.Level switch
        {
            LogEventLevel.Verbose or LogEventLevel.Debug => AppEventType.Debug,
            LogEventLevel.Information => AppEventType.Info,
            LogEventLevel.Warning => AppEventType.Warning,
            LogEventLevel.Error or LogEventLevel.Fatal => AppEventType.Error,
            _ => AppEventType.Event
        };

        Runtime.Event(logEvent.RenderMessage(), type);

        if (logEvent.Exception is not null)
        {
            Runtime.Event(
                logEvent.Exception.GetType().Name,
                AppEventType.Exception,
                logEvent.Exception.Message);
        }
    }
}

Attach the sink to your Serilog pipeline:

Log.Logger = new LoggerConfiguration()
    .WriteTo.Sink(new AnsightSerilogSink())
    .CreateLogger();

This works well when the rest of the app already uses Serilog sinks and enrichers and you want the same events mirrored into Ansight.

Sentry

Please use this skill /skills/dotnet/ansight-logging-sentry.md to integrate Ansight logging into Sentry.

Copyable prompt:

Please use this skill https://ansight.ai/skills/dotnet/ansight-logging-sentry.md to integrate Ansight logging into Sentry. Mirror the warnings and exceptions my app already sends to Sentry into Ansight with Runtime.Event(...), keep Sentry as the remote reporting system, and integrate at my app's existing capture points.

With Sentry, the practical integration point is usually the place where your app already captures a message or exception. Mirror that same capture into Ansight so the session timeline reflects what Sentry saw.

using Ansight;
using Ansight.Telemetry.Events;
using Sentry;

public static class AnsightSentryBridge
{
    public static void CaptureWarning(string message)
    {
        SentrySdk.CaptureMessage(message, SentryLevel.Warning);
        Runtime.Event(message, AppEventType.Warning);
    }

    public static void CaptureException(Exception exception)
    {
        SentrySdk.CaptureException(exception);
        Runtime.Event(exception.GetType().Name, AppEventType.Exception, exception.Message);
    }
}

Use this pattern when Sentry is your error-reporting system and you want the same warnings and exceptions to be visible in Ansight session analysis.

Why Logging Quality Matters

Screen views tell Ansight where the user was. Log events tell Ansight what happened there.

If you want better session analysis and better AI summaries, emit logs and events with:

  • stable labels
  • meaningful event types such as Info, Warning, and Error
  • compact structured details like route=/checkout, attempt=2, or httpStatus=500

Better logging leads to better metadata extraction. Sparse or inconsistent logs make it harder for analysis tools to explain the session clearly.

Capture Ansight Runtime Logs

Ansight exposes internal SDK diagnostics through ILogCallback.

This is only for Ansight’s own SDK diagnostics. It is not the primary mechanism for capturing your app’s Microsoft, Serilog, or Sentry logs into Ansight session data.

You have two main options:

  • WithBuiltInLogger() for simple console logging
  • WithAdditionalLogger(ILogCallback) to forward logs into your own logging sink

Built-In Console Logger

var options = Options.CreateBuilder()
    .WithBuiltInLogger()
    .Build();

Runtime.InitializeAndActivate(options);

Custom Logger

using Ansight;

public sealed class MyAnsightLogger : ILogCallback
{
    public string Name => "My Ansight Logger";

    public void Error(string message) => Console.WriteLine("ERROR " + message);
    public void Warning(string message) => Console.WriteLine("WARN " + message);
    public void Info(string message) => Console.WriteLine("INFO " + message);
    public void Exception(Exception exception) => Console.WriteLine("EXCEPTION " + exception);
}

var options = Options.CreateBuilder()
    .WithAdditionalLogger(new MyAnsightLogger())
    .Build();

Use this when you want Ansight diagnostics to appear in:

  • your app’s console output
  • an existing structured logger
  • a test harness log collector

This is separate from Runtime.Event(...):

  • Runtime.Event(...) is for app-level events you want captured in Ansight timelines and session analysis
  • ILogCallback is for Ansight’s own SDK diagnostics