--- name: ansight-logging-microsoft-extensions-logging description: Use this skill when integrating Microsoft.Extensions.Logging with Ansight so application logs are mirrored into Ansight session timelines through Runtime.Event. --- # Ansight Logging Skill For Microsoft.Extensions.Logging Use this skill when a user wants `Microsoft.Extensions.Logging` events to appear in Ansight session data. ## Goal Attach an Ansight-aware `ILoggerProvider` to the existing logging pipeline so application logs are mirrored into Ansight with `Runtime.Event(...)`. ## Required Constraints - keep the existing logging pipeline intact - add an Ansight receiver to `Microsoft.Extensions.Logging`; do not replace the app's current providers - do not treat `ILogCallback` as the primary solution for application logs - map log levels into `AppEventType` - capture exceptions as exception events when available ## Workflow 1. Inspect the existing `ILoggingBuilder` setup. 2. Add a custom `ILoggerProvider` and `ILogger` pair that forwards log entries into `Runtime.Event(...)`. 3. Map log levels: - `Trace` and `Debug` -> `AppEventType.Debug` - `Information` -> `AppEventType.Info` - `Warning` -> `AppEventType.Warning` - `Error` and `Critical` -> `AppEventType.Error` 4. Include useful metadata in `details`, such as category name and event id. 5. Register the provider alongside the app's existing providers. 6. Build and verify the app. ## Implementation Pattern ```csharp builder.Logging.AddProvider(new AnsightLoggerProvider()); ``` The provider should call `Runtime.Event(message, type, details)` for each log entry and emit a second `AppEventType.Exception` event when an exception is attached. ## Done Criteria - app logs now appear in Ansight timelines - existing console, debug, or structured providers still work - log levels are mapped consistently - exception details are not silently dropped