[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EA1TFF2KSMPZKVHKYGSSTP":3,"skill-same:01M7EA1TFF2KSMPZKVHKYGSSTP":102},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":13,"repositoryHtmlUrl":29,"repositoryHomepageUrl":6,"ownerHtmlUrl":30,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":31,"install":32,"resources":45},"01M7EA1TFF2KSMPZKVHKYGSSTP","dotnet-observability",null,"Logs, traces, and metrics in .NET code with ILogger, LoggerMessage, OpenTelemetry, and Azure Monitor (Application Insights). Use when code or a review touches ILogger, log levels, message templates, LoggerMessage, BeginScope, personal data or secrets in logs, log redaction, ActivitySource and spans, Meter, IMeterFactory, counters, OpenTelemetry setup (AddOpenTelemetry, UseOtlpExporter), Application Insights (connection string, UseMicrosoftOpenTelemetry, UseAzureMonitor, TelemetryClient), Serilog, trace sampling, or tests with FakeLogger and MetricCollector. Not for the middleware order or exception handlers (dev-stack:aspnetcore), an Aspire ServiceDefaults project (aspire), or dashboards and alert rules in a monitoring tool.","Charmedme\u002Fmaikelsoft-skills","Charmedme","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F11330182?v=4","01M7E9YWP4Z4JJ1BRXTMWNXAEV","01M7E9YWPS4N3GKRGAYBBDJWNQ",0,"MIT","https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: dotnet-observability\ndescription: Logs, traces, and metrics in .NET code with ILogger, LoggerMessage, OpenTelemetry, and Azure Monitor (Application Insights). Use when code or a review touches ILogger, log levels, message templates, LoggerMessage, BeginScope, personal data or secrets in logs, log redaction, ActivitySource and spans, Meter, IMeterFactory, counters, OpenTelemetry setup (AddOpenTelemetry, UseOtlpExporter), Application Insights (connection string, UseMicrosoftOpenTelemetry, UseAzureMonitor, TelemetryClient), Serilog, trace sampling, or tests with FakeLogger and MetricCollector. Not for the middleware order or exception handlers (dev-stack:aspnetcore), an Aspire ServiceDefaults project (aspire), or dashboards and alert rules in a monitoring tool.\nmetadata:\n  verified: \"2026-10-27\"\n  versions: \".NET 10, OpenTelemetry .NET 1.20.1, Microsoft.OpenTelemetry 1.2, Azure.Monitor.OpenTelemetry.AspNetCore 1.6, Microsoft.Extensions.Telemetry and Compliance.Redaction 10.11, Serilog 4.4 with Serilog.AspNetCore 10.0\"\n---\n\n# .NET observability\n\nLogs, traces, and metrics in application code, and the telemetry setup in `Program.cs`. Middleware and exception handlers: `dev-stack:aspnetcore`. A project with an Aspire ServiceDefaults project already wires OpenTelemetry there: use the `aspire` skill for that file.\n\n## First\n\n1. Read `references\u002Fstack-rules.md`.\n2. Find the telemetry packages in `*.csproj` or `Directory.Packages.props`:\n   - `Microsoft.OpenTelemetry` (the Microsoft OpenTelemetry Distro, `UseMicrosoftOpenTelemetry`) or `Azure.Monitor.OpenTelemetry.AspNetCore` (`UseAzureMonitor`): use this file.\n   - `Microsoft.ApplicationInsights.AspNetCore` 2.x, `Microsoft.Extensions.Logging.ApplicationInsights`, or `TelemetryConfiguration.Active`: read `references\u002Fappinsights.md` before you change code.\n   - `Serilog.AspNetCore`: read `references\u002Fserilog.md`.\n   - Only `OpenTelemetry.*` packages: use this file.\n3. Read `.editorconfig` and `Directory.Build.props` for the log analyzer settings (CA1848, CA1873, `AnalysisLevel`).\n\nDone when you can name the telemetry client, the logging pipeline (MEL or Serilog), and the CA1848 setting.\n\n## Defaults for new code\n\nAsk the human before you apply a default that has no accepted decision (stack rule 4). The full entries are in `references\u002Fdecisions.md`.\n\n| Area | Default | ID |\n|------|---------|----|\n| Backend | Azure Monitor (Application Insights) on Azure. Grafana stack elsewhere. Code uses OpenTelemetry APIs only. | OPS-18 |\n| Azure Monitor client | Microsoft OpenTelemetry Distro for a new app. Keep `UseAzureMonitor` where it exists. | OPS-24 |\n| Pipeline | Microsoft.Extensions.Logging plus OpenTelemetry. Serilog only where it exists or on request. | OPS-23 |\n| Log style | `[LoggerMessage]` in services and libraries. The project setting wins. | OPS-23 |\n| Log format | OTLP export, JSON console in containers (`Logging__Console__FormatterName=Json`). | OPS-19 |\n| Sampling | Keep all traces, set in configuration. Ratio sampling above about 100 requests per second. | OPS-20 |\n| Personal data | Classify and redact. HMAC when support must search by the value. | SEC-14 |\n\nExisting code keeps its style (stack rule 3).\n\n## Rules\n\n### Pipeline and client\n\n1. Keep one logging pipeline: Microsoft.Extensions.Logging (MEL) plus OpenTelemetry. `AddSerilog()` replaces the `ILoggerFactory`. Then other logger providers (also the provider of the Azure Monitor distro) get nothing unless `writeToProviders: true`, and compliance redaction stops.\n2. New app on Azure: call `UseMicrosoftOpenTelemetry` with `ExportTarget.AzureMonitor`. Keep `UseAzureMonitor` where it exists. Use one distro: `UseAzureMonitor` plus `UseMicrosoftOpenTelemetry` stops the host with `NotSupportedException` (\"Multiple calls to UseAzureMonitorExporter\").\n3. Register the distro only when the connection string is set. Without `APPLICATIONINSIGHTS_CONNECTION_STRING` it throws `InvalidOperationException` at host start, so local runs and `WebApplicationFactory` tests fail. The package has no public guard method: read the configuration value.\n4. Read the connection string from configuration (`APPLICATIONINSIGHTS_CONNECTION_STRING`, from the environment or a secret store). Do not use an instrumentation key: key ingestion is out of support since 2025-03-31.\n5. Set sampling in code or configuration (OPS-20). `SamplingRatio` alone changes nothing: its default is already 1.0, and `TracesPerSecond` (default 5) wins when both have a value. So `SamplingRatio = 1.0F` alone keeps about 5 traces per second (Azure Monitor distro 1.5.0 and later). The trace-based log sampler (on by default) then drops the logs of the other traces. Set `TracesPerSecond = null` next to `SamplingRatio`. In a review, a `SamplingRatio` without `TracesPerSecond = null` is a high finding. Microsoft distro 1.2.0 caveat: `references\u002Fappinsights.md`.\n6. Register each own `ActivitySource` and `Meter` by name. With the distro, call `ConfigureOpenTelemetryTracerProvider` and `ConfigureOpenTelemetryMeterProvider`. Without a registration, `StartActivity` returns null and the counter records nothing.\n\n```csharp\n\u002F\u002F Program.cs. Packages: Microsoft.OpenTelemetry, Microsoft.Extensions.Telemetry, Microsoft.Extensions.Compliance.Redaction.\nbuilder.Logging.EnableRedaction();\nbuilder.Services.AddRedaction(redaction => redaction.SetHmacRedactor(\n    options =>\n    {\n        options.KeyId = 1;\n        options.Key = builder.Configuration[\"Redaction:HmacKey\"]!; \u002F\u002F base64, from the secret store\n    },\n    new DataClassificationSet(DataTaxonomy.Personal)));\n\n\u002F\u002F The distro throws at start without a connection string (local runs, tests).\nif (!string.IsNullOrWhiteSpace(builder.Configuration[\"APPLICATIONINSIGHTS_CONNECTION_STRING\"]))\n{\n    builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddSource(Telemetry.Name));\n    builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddMeter(Telemetry.Name));\n    builder.Services.Configure\u003COpenTelemetryLoggerOptions>(logging => logging.IncludeScopes = true); \u002F\u002F rule 11\n    builder.UseMicrosoftOpenTelemetry(options =>\n    {\n        options.Exporters = ExportTarget.AzureMonitor;\n        options.AzureMonitor.SamplingRatio = 1.0F; \u002F\u002F OPS-20: keep all traces\n        options.AzureMonitor.TracesPerSecond = null;\n    });\n}\n```\n\nWithout Azure, use the OpenTelemetry SDK with `.UseOtlpExporter()` one time for all signals. Example and options: `references\u002Fappinsights.md`.\n\n### Log calls\n\n7. Use a message template with PascalCase placeholders. Do not use string interpolation or concatenation in a log call. The analyzers report it: CA2254 (template varies), CA2017 (placeholder count), CA2253 (numeric placeholder), CA1727 (placeholder case).\n8. Write new log calls as `[LoggerMessage]` methods with a unique `EventId` per class (OPS-23). CA1873 warns on each `LogTrace`, `LogDebug`, or `LogInformation` call that passes arguments, also when the project turns CA1848 off. With `-warnaserror` the build then fails. Existing code keeps its style.\n9. Pass the exception as the exception argument, not `ex.Message`. Log a failure one time, at the boundary that handles it. A log and a rethrow give two entries for one failure.\n10. Do not log secrets, tokens, connection strings, full bodies, or headers. Classify personal data with a `DataClassificationAttribute` (for example `[PersonalData] string email`), and turn on `EnableRedaction` with `AddRedaction`. Use the HMAC redactor when support must search by the value: the log then holds `\u003Ckey id>:\u003Chash>`. Redaction works only in the MEL logger factory.\n11. Log scopes are off by default in OpenTelemetry, also with both distros (`OpenTelemetryLoggerOptions.IncludeScopes` is false). When code or support depends on a `BeginScope` value (for example a filter on `customDimensions.ShipmentId`), set `IncludeScopes = true`. Or put the value in the log event itself. Existing scope use without this setting is a finding: those values never reached the backend.\n\n```csharp\ninternal static partial class OrderLog\n{\n    [LoggerMessage(EventId = 1001, Level = LogLevel.Information, Message = \"Order {OrderId} created for customer {CustomerId} ({CustomerEmail})\")]\n    public static partial void OrderCreated(ILogger logger, Guid orderId, Guid customerId, [PersonalData] string? customerEmail);\n\n    [LoggerMessage(EventId = 1002, Level = LogLevel.Error, Message = \"Creating an order for customer {CustomerId} failed\")]\n    public static partial void CreateFailed(ILogger logger, Exception exception, Guid customerId);\n}\n```\n\nTaxonomy, attributes, the HMAC key, and security events: `references\u002Fredaction.md`.\n\n### Traces and metrics\n\n12. Use one `static readonly ActivitySource` per component. Use `activity?.` on the result of `StartActivity`: it is null when no listener samples the trace.\n13. Create meters through `IMeterFactory` (`meterFactory.Create(name)`), not with `new Meter(...)`. The factory owns the meter and disposes it, and tests can collect its measurements.\n14. Keep metric tags low-cardinality: a status, a channel, a region, a kind. Put no customer ID, email, or order ID on a metric. Each value makes a new time series, and the tag puts personal data in metrics. Put IDs on spans and logs. A count per customer is a query on logs or spans.\n15. Add `AddConsoleExporter()` only in development. In production it writes each span and metric to stdout.\n\n```csharp\npublic sealed class OrdersTelemetry\n{\n    public const string Name = \"Orders.Api\";\n    public static readonly ActivitySource Source = new(Name);\n    private readonly Counter\u003Clong> _created;\n\n    public OrdersTelemetry(IMeterFactory meterFactory) =>\n        _created = meterFactory.Create(Name).CreateCounter\u003Clong>(\"orders.created\", unit: \"{order}\");\n\n    public void OrderCreated(string channel) =>\n        _created.Add(1, new KeyValuePair\u003Cstring, object?>(\"orders.channel\", channel));\n}\n```\n\n### Tests\n\n16. Test log output with `FakeLogger` (package `Microsoft.Extensions.Diagnostics.Testing`). Assert the level, the `EventId`, and the structured values. Assert that the record holds no raw personal data. Get the logger from a service provider with `EnableRedaction()` and `AddFakeLogging()`: a bare `new FakeLogger\u003CT>()` shows classified values as `(null)`. Test metrics with `MetricCollector\u003CT>`. Keep the distro off in tests (rule 3).\n\nExamples: `references\u002Ftesting.md`.\n\n## Never write\n\n| Wrong | Correct |\n|-------|---------|\n| `services.AddApplicationInsightsTelemetry(\"\u003Ckey>\")`, `\"InstrumentationKey\": \"...\"` | Connection string from `APPLICATIONINSIGHTS_CONNECTION_STRING`, `UseMicrosoftOpenTelemetry` for a new app |\n| `new TelemetryClient(TelemetryConfiguration.Active)` | `TelemetryClient` from DI (SDK 3.x), or an `ActivitySource` and a `Meter` |\n| `builder.Logging.AddApplicationInsights();` | Nothing: the distro collects `ILogger` logs |\n| `builder.UseMicrosoftOpenTelemetry(...)` without a check | Register it only when the connection string is set |\n| `.UseAzureMonitor()` and `UseMicrosoftOpenTelemetry(...)` together | One distro |\n| `builder.Host.UseSerilog(...)` | MEL plus OpenTelemetry. Where Serilog stays: `builder.Services.AddSerilog(..., writeToProviders: true)` |\n| `.WriteTo.ApplicationInsights(TelemetryConfiguration.Active, ...)` | `AddSerilog(..., writeToProviders: true)` plus the distro, or MEL only |\n| `logger.LogInformation($\"Order {id} shipped\")` | `[LoggerMessage(EventId = 1001, Message = \"Order {OrderId} shipped\")]` |\n| `logger.LogError(\"Failed: \" + ex.Message)` | `OrderLog.CreateFailed(logger, ex, customerId)` |\n| `private readonly Meter _meter = new(\"Orders\");` | `meterFactory.Create(\"Orders.Api\")` |\n| `_created.Add(1, new(\"customer.id\", customerId))` | `_created.Add(1, new(\"orders.channel\", channel))` |\n| `EnableAdaptiveSampling = false` | `SamplingRatio` and `TracesPerSecond` |\n| `options.SamplingRatio = 1.0F;` alone | `SamplingRatio = 1.0F` and `TracesPerSecond = null` |\n| `.AddConsoleExporter()` in all environments | `.UseOtlpExporter()`, console only in development |\n| `new FakeLogger\u003CT>()` to test classified values | A logger from a provider with `EnableRedaction()` and `AddFakeLogging()` |\n\n## Check\n\n1. Build with the analyzers as errors:\n\n   ```\n   dotnet build -warnaserror\n   ```\n\n   Pass: `Build succeeded` with 0 warnings. With `AnalysisLevel` `latest-recommended`, CA2254, CA2017, CA2253, CA1727, and CA1873 run. CA1848 runs where the project keeps it on.\n\n2. List the telemetry packages:\n\n   ```\n   dotnet package list --include-transitive\n   ```\n\n   Pass: no `Microsoft.Extensions.Logging.ApplicationInsights`, no `Microsoft.ApplicationInsights` below 3.0, no `Serilog.Sinks.ApplicationInsights` next to SDK 3.x, and one distro.\n\n3. Run the tests without `APPLICATIONINSIGHTS_CONNECTION_STRING`: `dotnet test`. Pass: all green. A `FakeLogger` test proves that the raw personal data is not in the log.\n\n4. Run the rules of this skill:\n\n   ```\n   python3 \u003Cskill folder>\u002Fscripts\u002Fstackcheck.py --root \u003Crepo>\n   ```\n\n   Pass: 0 errors. For each warning, fix it or add `\u002F\u002F stackcheck: ignore \u003CRULE-ID> \u003Creason>`.\n\n## Review checklist\n\nThe full list is in `references\u002Freview-checklist.md`.\n\n1. One logging pipeline. Serilog only with `writeToProviders: true` or without other providers. tool (OBS-USE-SERILOG), judge\n2. One distro, registered only when the connection string is set. tool (OBS-TWO-DISTROS), judge\n3. No instrumentation key, no classic Application Insights API. tool (OBS-IKEY, OBS-AI-CLASSIC, OBS-PKG-MEL-AI, OBS-PKG-AI-2X)\n4. Sampling is explicit (OPS-20): `TracesPerSecond = null` next to each `SamplingRatio`. judge\n5. Own sources and meters are registered by name. judge\n6. Message templates only, no interpolation. tool (CA2254, CA2017, CA2253, CA1727)\n7. New log calls are `[LoggerMessage]` methods or follow the project style. tool (CA1873, CA1848), judge\n8. The exception is the exception argument. Each failure is logged one time. judge\n9. No secrets or raw personal data in logs. Personal data is classified and redacted with the MEL factory. judge\n10. Metric tags are low-cardinality. No IDs or emails on metrics. judge\n11. Meters come from `IMeterFactory`. tool (OBS-NEW-METER)\n12. No console exporter in production. tool (OBS-CONSOLE-EXPORTER)\n13. `StartActivity` results use `activity?.`. tool (CS8602)\n14. Tests prove the log and metric behavior with `FakeLogger` and `MetricCollector\u003CT>`. judge\n15. Scope values that code or support depends on reach the backend (`IncludeScopes = true`). judge\n\n## Report\n\nEnd with the report of stack rule 8 (`references\u002Fstack-rules.md`): the same headings in the same order on each run.\n\n## References\n\n- `references\u002Fdecisions.md`: read before new code needs an OPS-18, OPS-19, OPS-20, OPS-23, or OPS-24 decision. It has the question, the options, and the recommendation.\n- `references\u002Fappinsights.md`: read when the project uses Application Insights, when you choose between the distros, or when you migrate from SDK 2.x or an instrumentation key. It also has the OTLP setup.\n- `references\u002Fredaction.md`: read before you log a value that can be personal data or a secret, or a security event.\n- `references\u002Fserilog.md`: read when the project has Serilog or the human asks for it.\n- `references\u002Ftesting.md`: read before you write a test for logs, spans, or metrics.\n- `references\u002Freview-checklist.md`: read for a full review.\n- `references\u002Fsources.md`: the primary sources and the credits.\n- `references\u002Fstack-rules.md` and `references\u002Flanguage.md`: the common rules and the output language. Output follows `references\u002Flanguage.md`.\n- `scripts\u002Fstackcheck.py`: the rule check of this skill.\n","# .NET observability\n\nLogs, traces, and metrics in application code, and the telemetry setup in `Program.cs`. Middleware and exception handlers: `dev-stack:aspnetcore`. A project with an Aspire ServiceDefaults project already wires OpenTelemetry there: use the `aspire` skill for that file.\n\n## First\n\n1. Read `references\u002Fstack-rules.md`.\n2. Find the telemetry packages in `*.csproj` or `Directory.Packages.props`:\n   - `Microsoft.OpenTelemetry` (the Microsoft OpenTelemetry Distro, `UseMicrosoftOpenTelemetry`) or `Azure.Monitor.OpenTelemetry.AspNetCore` (`UseAzureMonitor`): use this file.\n   - `Microsoft.ApplicationInsights.AspNetCore` 2.x, `Microsoft.Extensions.Logging.ApplicationInsights`, or `TelemetryConfiguration.Active`: read `references\u002Fappinsights.md` before you change code.\n   - `Serilog.AspNetCore`: read `references\u002Fserilog.md`.\n   - Only `OpenTelemetry.*` packages: use this file.\n3. Read `.editorconfig` and `Directory.Build.props` for the log analyzer settings (CA1848, CA1873, `AnalysisLevel`).\n\nDone when you can name the telemetry client, the logging pipeline (MEL or Serilog), and the CA1848 setting.\n\n## Defaults for new code\n\nAsk the human before you apply a default that has no accepted decision (stack rule 4). The full entries are in `references\u002Fdecisions.md`.\n\n| Area | Default | ID |\n|------|---------|----|\n| Backend | Azure Monitor (Application Insights) on Azure. Grafana stack elsewhere. Code uses OpenTelemetry APIs only. | OPS-18 |\n| Azure Monitor client | Microsoft OpenTelemetry Distro for a new app. Keep `UseAzureMonitor` where it exists. | OPS-24 |\n| Pipeline | Microsoft.Extensions.Logging plus OpenTelemetry. Serilog only where it exists or on request. | OPS-23 |\n| Log style | `[LoggerMessage]` in services and libraries. The project setting wins. | OPS-23 |\n| Log format | OTLP export, JSON console in containers (`Logging__Console__FormatterName=Json`). | OPS-19 |\n| Sampling | Keep all traces, set in configuration. Ratio sampling above about 100 requests per second. | OPS-20 |\n| Personal data | Classify and redact. HMAC when support must search by the value. | SEC-14 |\n\nExisting code keeps its style (stack rule 3).\n\n## Rules\n\n### Pipeline and client\n\n1. Keep one logging pipeline: Microsoft.Extensions.Logging (MEL) plus OpenTelemetry. `AddSerilog()` replaces the `ILoggerFactory`. Then other logger providers (also the provider of the Azure Monitor distro) get nothing unless `writeToProviders: true`, and compliance redaction stops.\n2. New app on Azure: call `UseMicrosoftOpenTelemetry` with `ExportTarget.AzureMonitor`. Keep `UseAzureMonitor` where it exists. Use one distro: `UseAzureMonitor` plus `UseMicrosoftOpenTelemetry` stops the host with `NotSupportedException` (\"Multiple calls to UseAzureMonitorExporter\").\n3. Register the distro only when the connection string is set. Without `APPLICATIONINSIGHTS_CONNECTION_STRING` it throws `InvalidOperationException` at host start, so local runs and `WebApplicationFactory` tests fail. The package has no public guard method: read the configuration value.\n4. Read the connection string from configuration (`APPLICATIONINSIGHTS_CONNECTION_STRING`, from the environment or a secret store). Do not use an instrumentation key: key ingestion is out of support since 2025-03-31.\n5. Set sampling in code or configuration (OPS-20). `SamplingRatio` alone changes nothing: its default is already 1.0, and `TracesPerSecond` (default 5) wins when both have a value. So `SamplingRatio = 1.0F` alone keeps about 5 traces per second (Azure Monitor distro 1.5.0 and later). The trace-based log sampler (on by default) then drops the logs of the other traces. Set `TracesPerSecond = null` next to `SamplingRatio`. In a review, a `SamplingRatio` without `TracesPerSecond = null` is a high finding. Microsoft distro 1.2.0 caveat: `references\u002Fappinsights.md`.\n6. Register each own `ActivitySource` and `Meter` by name. With the distro, call `ConfigureOpenTelemetryTracerProvider` and `ConfigureOpenTelemetryMeterProvider`. Without a registration, `StartActivity` returns null and the counter records nothing.\n\n```csharp\n\u002F\u002F Program.cs. Packages: Microsoft.OpenTelemetry, Microsoft.Extensions.Telemetry, Microsoft.Extensions.Compliance.Redaction.\nbuilder.Logging.EnableRedaction();\nbuilder.Services.AddRedaction(redaction => redaction.SetHmacRedactor(\n    options =>\n    {\n        options.KeyId = 1;\n        options.Key = builder.Configuration[\"Redaction:HmacKey\"]!; \u002F\u002F base64, from the secret store\n    },\n    new DataClassificationSet(DataTaxonomy.Personal)));\n\n\u002F\u002F The distro throws at start without a connection string (local runs, tests).\nif (!string.IsNullOrWhiteSpace(builder.Configuration[\"APPLICATIONINSIGHTS_CONNECTION_STRING\"]))\n{\n    builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddSource(Telemetry.Name));\n    builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddMeter(Telemetry.Name));\n    builder.Services.Configure\u003COpenTelemetryLoggerOptions>(logging => logging.IncludeScopes = true); \u002F\u002F rule 11\n    builder.UseMicrosoftOpenTelemetry(options =>\n    {\n        options.Exporters = ExportTarget.AzureMonitor;\n        options.AzureMonitor.SamplingRatio = 1.0F; \u002F\u002F OPS-20: keep all traces\n        options.AzureMonitor.TracesPerSecond = null;\n    });\n}\n```\n\nWithout Azure, use the OpenTelemetry SDK with `.UseOtlpExporter()` one time for all signals. Example and options: `references\u002Fappinsights.md`.\n\n### Log calls\n\n7. Use a message template with PascalCase placeholders. Do not use string interpolation or concatenation in a log call. The analyzers report it: CA2254 (template varies), CA2017 (placeholder count), CA2253 (numeric placeholder), CA1727 (placeholder case).\n8. Write new log calls as `[LoggerMessage]` methods with a unique `EventId` per class (OPS-23). CA1873 warns on each `LogTrace`, `LogDebug`, or `LogInformation` call that passes arguments, also when the project turns CA1848 off. With `-warnaserror` the build then fails. Existing code keeps its style.\n9. Pass the exception as the exception argument, not `ex.Message`. Log a failure one time, at the boundary that handles it. A log and a rethrow give two entries for one failure.\n10. Do not log secrets, tokens, connection strings, full bodies, or headers. Classify personal data with a `DataClassificationAttribute` (for example `[PersonalData] string email`), and turn on `EnableRedaction` with `AddRedaction`. Use the HMAC redactor when support must search by the value: the log then holds `\u003Ckey id>:\u003Chash>`. Redaction works only in the MEL logger factory.\n11. Log scopes are off by default in OpenTelemetry, also with both distros (`OpenTelemetryLoggerOptions.IncludeScopes` is false). When code or support depends on a `BeginScope` value (for example a filter on `customDimensions.ShipmentId`), set `IncludeScopes = true`. Or put the value in the log event itself. Existing scope use without this setting is a finding: those values never reached the backend.\n\n```csharp\ninternal static partial class OrderLog\n{\n    [LoggerMessage(EventId = 1001, Level = LogLevel.Information, Message = \"Order {OrderId} created for customer {CustomerId} ({CustomerEmail})\")]\n    public static partial void OrderCreated(ILogger logger, Guid orderId, Guid customerId, [PersonalData] string? customerEmail);\n\n    [LoggerMessage(EventId = 1002, Level = LogLevel.Error, Message = \"Creating an order for customer {CustomerId} failed\")]\n    public static partial void CreateFailed(ILogger logger, Exception exception, Guid customerId);\n}\n```\n\nTaxonomy, attributes, the HMAC key, and security events: `references\u002Fredaction.md`.\n\n### Traces and metrics\n\n12. Use one `static readonly ActivitySource` per component. Use `activity?.` on the result of `StartActivity`: it is null when no listener samples the trace.\n13. Create meters through `IMeterFactory` (`meterFactory.Create(name)`), not with `new Meter(...)`. The factory owns the meter and disposes it, and tests can collect its measurements.\n14. Keep metric tags low-cardinality: a status, a channel, a region, a kind. Put no customer ID, email, or order ID on a metric. Each value makes a new time series, and the tag puts personal data in metrics. Put IDs on spans and logs. A count per customer is a query on logs or spans.\n15. Add `AddConsoleExporter()` only in development. In production it writes each span and metric to stdout.\n\n```csharp\npublic sealed class OrdersTelemetry\n{\n    public const string Name = \"Orders.Api\";\n    public static readonly ActivitySource Source = new(Name);\n    private readonly Counter\u003Clong> _created;\n\n    public OrdersTelemetry(IMeterFactory meterFactory) =>\n        _created = meterFactory.Create(Name).CreateCounter\u003Clong>(\"orders.created\", unit: \"{order}\");\n\n    public void OrderCreated(string channel) =>\n        _created.Add(1, new KeyValuePair\u003Cstring, object?>(\"orders.channel\", channel));\n}\n```\n\n### Tests\n\n16. Test log output with `FakeLogger` (package `Microsoft.Extensions.Diagnostics.Testing`). Assert the level, the `EventId`, and the structured values. Assert that the record holds no raw personal data. Get the logger from a service provider with `EnableRedaction()` and `AddFakeLogging()`: a bare `new FakeLogger\u003CT>()` shows classified values as `(null)`. Test metrics with `MetricCollector\u003CT>`. Keep the distro off in tests (rule 3).\n\nExamples: `references\u002Ftesting.md`.\n\n## Never write\n\n| Wrong | Correct |\n|-------|---------|\n| `services.AddApplicationInsightsTelemetry(\"\u003Ckey>\")`, `\"InstrumentationKey\": \"...\"` | Connection string from `APPLICATIONINSIGHTS_CONNECTION_STRING`, `UseMicrosoftOpenTelemetry` for a new app |\n| `new TelemetryClient(TelemetryConfiguration.Active)` | `TelemetryClient` from DI (SDK 3.x), or an `ActivitySource` and a `Meter` |\n| `builder.Logging.AddApplicationInsights();` | Nothing: the distro collects `ILogger` logs |\n| `builder.UseMicrosoftOpenTelemetry(...)` without a check | Register it only when the connection string is set |\n| `.UseAzureMonitor()` and `UseMicrosoftOpenTelemetry(...)` together | One distro |\n| `builder.Host.UseSerilog(...)` | MEL plus OpenTelemetry. Where Serilog stays: `builder.Services.AddSerilog(..., writeToProviders: true)` |\n| `.WriteTo.ApplicationInsights(TelemetryConfiguration.Active, ...)` | `AddSerilog(..., writeToProviders: true)` plus the distro, or MEL only |\n| `logger.LogInformation($\"Order {id} shipped\")` | `[LoggerMessage(EventId = 1001, Message = \"Order {OrderId} shipped\")]` |\n| `logger.LogError(\"Failed: \" + ex.Message)` | `OrderLog.CreateFailed(logger, ex, customerId)` |\n| `private readonly Meter _meter = new(\"Orders\");` | `meterFactory.Create(\"Orders.Api\")` |\n| `_created.Add(1, new(\"customer.id\", customerId))` | `_created.Add(1, new(\"orders.channel\", channel))` |\n| `EnableAdaptiveSampling = false` | `SamplingRatio` and `TracesPerSecond` |\n| `options.SamplingRatio = 1.0F;` alone | `SamplingRatio = 1.0F` and `TracesPerSecond = null` |\n| `.AddConsoleExporter()` in all environments | `.UseOtlpExporter()`, console only in development |\n| `new FakeLogger\u003CT>()` to test classified values | A logger from a provider with `EnableRedaction()` and `AddFakeLogging()` |\n\n## Check\n\n1. Build with the analyzers as errors:\n\n   ```\n   dotnet build -warnaserror\n   ```\n\n   Pass: `Build succeeded` with 0 warnings. With `AnalysisLevel` `latest-recommended`, CA2254, CA2017, CA2253, CA1727, and CA1873 run. CA1848 runs where the project keeps it on.\n\n2. List the telemetry packages:\n\n   ```\n   dotnet package list --include-transitive\n   ```\n\n   Pass: no `Microsoft.Extensions.Logging.ApplicationInsights`, no `Microsoft.ApplicationInsights` below 3.0, no `Serilog.Sinks.ApplicationInsights` next to SDK 3.x, and one distro.\n\n3. Run the tests without `APPLICATIONINSIGHTS_CONNECTION_STRING`: `dotnet test`. Pass: all green. A `FakeLogger` test proves that the raw personal data is not in the log.\n\n4. Run the rules of this skill:\n\n   ```\n   python3 \u003Cskill folder>\u002Fscripts\u002Fstackcheck.py --root \u003Crepo>\n   ```\n\n   Pass: 0 errors. For each warning, fix it or add `\u002F\u002F stackcheck: ignore \u003CRULE-ID> \u003Creason>`.\n\n## Review checklist\n\nThe full list is in `references\u002Freview-checklist.md`.\n\n1. One logging pipeline. Serilog only with `writeToProviders: true` or without other providers. tool (OBS-USE-SERILOG), judge\n2. One distro, registered only when the connection string is set. tool (OBS-TWO-DISTROS), judge\n3. No instrumentation key, no classic Application Insights API. tool (OBS-IKEY, OBS-AI-CLASSIC, OBS-PKG-MEL-AI, OBS-PKG-AI-2X)\n4. Sampling is explicit (OPS-20): `TracesPerSecond = null` next to each `SamplingRatio`. judge\n5. Own sources and meters are registered by name. judge\n6. Message templates only, no interpolation. tool (CA2254, CA2017, CA2253, CA1727)\n7. New log calls are `[LoggerMessage]` methods or follow the project style. tool (CA1873, CA1848), judge\n8. The exception is the exception argument. Each failure is logged one time. judge\n9. No secrets or raw personal data in logs. Personal data is classified and redacted with the MEL factory. judge\n10. Metric tags are low-cardinality. No IDs or emails on metrics. judge\n11. Meters come from `IMeterFactory`. tool (OBS-NEW-METER)\n12. No console exporter in production. tool (OBS-CONSOLE-EXPORTER)\n13. `StartActivity` results use `activity?.`. tool (CS8602)\n14. Tests prove the log and metric behavior with `FakeLogger` and `MetricCollector\u003CT>`. judge\n15. Scope values that code or support depends on reach the backend (`IncludeScopes = true`). judge\n\n## Report\n\nEnd with the report of stack rule 8 (`references\u002Fstack-rules.md`): the same headings in the same order on each run.\n\n## References\n\n- `references\u002Fdecisions.md`: read before new code needs an OPS-18, OPS-19, OPS-20, OPS-23, or OPS-24 decision. It has the question, the options, and the recommendation.\n- `references\u002Fappinsights.md`: read when the project uses Application Insights, when you choose between the distros, or when you migrate from SDK 2.x or an instrumentation key. It also has the OTLP setup.\n- `references\u002Fredaction.md`: read before you log a value that can be personal data or a secret, or a security event.\n- `references\u002Fserilog.md`: read when the project has Serilog or the human asks for it.\n- `references\u002Ftesting.md`: read before you write a test for logs, spans, or metrics.\n- `references\u002Freview-checklist.md`: read for a full review.\n- `references\u002Fsources.md`: the primary sources and the credits.\n- `references\u002Fstack-rules.md` and `references\u002Flanguage.md`: the common rules and the output language. Output follows `references\u002Flanguage.md`.\n- `scripts\u002Fstackcheck.py`: the rule check of this skill.\n",{"name":5,"metadata":23,"description":7},{"verified":24,"versions":25},"2026-10-27",".NET 10, OpenTelemetry .NET 1.20.1, Microsoft.OpenTelemetry 1.2, Azure.Monitor.OpenTelemetry.AspNetCore 1.6, Microsoft.Extensions.Telemetry and Compliance.Redaction 10.11, Serilog 4.4 with Serilog.AspNetCore 10.0","main","c247fa77bdea99449b9df09f93d92a35fed91874","plugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability","https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills","https:\u002F\u002Fgithub.com\u002FCharmedme","2026-11-13 14:41:21",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add Charmedme\u002Fmaikelsoft-skills --skill dotnet-observability",{"tool":38,"command":39},"bunx","bunx skills add Charmedme\u002Fmaikelsoft-skills --skill dotnet-observability",{"tool":41,"command":42},"pnpm","pnpm dlx skills add Charmedme\u002Fmaikelsoft-skills --skill dotnet-observability","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002FSKILL.md",true,[46,52,56,60,64,68,72,76,80,84,88,94,98],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"references\u002Fappinsights.md","REFERENCE","参考文档",7166,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Freferences\u002Fappinsights.md",{"path":53,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":54,"sourceHtmlUrl":55},"references\u002Fdecisions.md",5631,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Freferences\u002Fdecisions.md",{"path":57,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":58,"sourceHtmlUrl":59},"references\u002Flanguage.md",4840,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Freferences\u002Flanguage.md",{"path":61,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":62,"sourceHtmlUrl":63},"references\u002Fredaction.md",4211,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Freferences\u002Fredaction.md",{"path":65,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":66,"sourceHtmlUrl":67},"references\u002Freview-checklist.md",4412,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Freferences\u002Freview-checklist.md",{"path":69,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":70,"sourceHtmlUrl":71},"references\u002Fserilog.md",2460,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Freferences\u002Fserilog.md",{"path":73,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":74,"sourceHtmlUrl":75},"references\u002Fsources.md",9220,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Freferences\u002Fsources.md",{"path":77,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":78,"sourceHtmlUrl":79},"references\u002Fstack-rules.md",7772,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Freferences\u002Fstack-rules.md",{"path":81,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":82,"sourceHtmlUrl":83},"references\u002Ftesting.md",3057,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Freferences\u002Ftesting.md",{"path":85,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":86,"sourceHtmlUrl":87},"rules.json",8688,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Frules.json",{"path":89,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":92,"sourceHtmlUrl":93},"scripts\u002Fconvert.py","SCRIPT","脚本",2928,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Fscripts\u002Fconvert.py",{"path":95,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":96,"sourceHtmlUrl":97},"scripts\u002Fdoccheck.py",29463,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Fscripts\u002Fdoccheck.py",{"path":99,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":100,"sourceHtmlUrl":101},"scripts\u002Fstackcheck.py",12200,"https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fdev-stack\u002Fskills\u002Fdotnet-observability\u002Fscripts\u002Fstackcheck.py",[103,110,117,124,131,138],{"skillNo":104,"name":105,"nameZh":6,"description":106,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":107,"categories":108,"keywords":109,"publishedAt":18},"01M7EA9S53810TTZTXYDGBWXHY","web-accessibility","Web accessibility to WCAG 2.2 AA - a checklist for the design, the tool checks (axe-core, the Tab walk, reduced motion), and the manual checks that no tool does (screen reader, zoom, status messages) - with the EAA and EN 301 549 status. Use when a design, mockup, or built feature must be checked for accessibility, when a review must cover keyboard and screen reader use, when the user asks about focus, a focus trap, contrast, or a screen reader on a page, or when the user asks which accessibility rules apply.","https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fux-design\u002Fskills\u002Fweb-accessibility\u002FSKILL.md",[],[],{"skillNo":111,"name":112,"nameZh":6,"description":113,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":18},"01M7EA9MGJ7ESKQ7WE2Z96858T","ux-states","State inventory for each screen - default, empty, loading, partial, error, success, disabled, overflow, offline, and the business states (no permission, stale data, locked by another user, waiting on an external system, bulk result with failures, read only) - with what the user sees, can do, and how the user recovers. Use when a screen or flow needs its states designed or checked, or when a design shows only the happy path.","https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fux-design\u002Fskills\u002Fux-states\u002FSKILL.md",[],[],{"skillNo":118,"name":119,"nameZh":6,"description":120,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":121,"categories":122,"keywords":123,"publishedAt":18},"01M7EA9FHYR0C26BHNQF7AZT4Q","ux-setup","Set up a project for UX work - finds the design tools, the design-system source, the brand files, the languages, and the run command, asks the human one round of questions, and writes the \"## Design\" section of .claude\u002Frules\u002Fdelivery.md that the ux-design commands and the ux-designer agent read. Moves an older \"## Design\" section out of CLAUDE.md. Use when \u002Fsetup, \u002Fux-design, or \u002Fux-review needs the design facts, when the ux-designer agent returns NEEDS_HUMAN because the \"## Design\" section is missing, or when the user wants to set up or change the design tools of a project.","https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fux-design\u002Fskills\u002Fux-setup\u002FSKILL.md",[],[],{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":130,"publishedAt":18},"01M7EA99DQDFVJQBJNYDJQC643","ux-review","UX review of a built feature against its approved design - Playwright walks each flow and state at 390, 820, and 1440 px, axe-core and the tell checks run on each state, and each heuristic gets a verdict - with findings by owner, severity, and origin, and a verdict in ux-review.md in the work folder of the item. Use when a built feature or screen must be checked against its design, mockups, or prototype, in each state or at each screen size, when built screens need findings by severity, when the build of an item with a UX design is done, or when existing screens need a UX audit.","https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fux-design\u002Fskills\u002Fux-review\u002FSKILL.md",[],[],{"skillNo":132,"name":133,"nameZh":6,"description":134,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":135,"categories":136,"keywords":137,"publishedAt":18},"01M7EA95YPJQQ1YDW5HS0RVAN2","ux-prototype","Clickable prototype of a designed story in the proto-shell standard, with variants for an A\u002FB test, all states in scope, three sizes, and a test plan with tasks. Use when a design or mockups exist and the team must test the flow or compare variants with users before the build.","https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fux-design\u002Fskills\u002Fux-prototype\u002FSKILL.md",[],[],{"skillNo":139,"name":140,"nameZh":6,"description":141,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":142,"categories":143,"keywords":144,"publishedAt":18},"01M7EA91SKA2RNFGW9VDG9JFW7","ux-practice","The method of the ux-designer agent for the UX design of a story, a feature, or a screen - Double Diamond phases, a design spec with a source for each decision, the UX decision log, evidence tags, severity, and the modes light, full, and new-direction. Preloaded by the ux-designer agent. Use when the ux-designer agent or another UX skill names this method. For the design of an item, a person starts ux-design:ux-design.","https:\u002F\u002Fgithub.com\u002FCharmedme\u002Fmaikelsoft-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fux-design\u002Fskills\u002Fux-practice\u002FSKILL.md",[],[]]