{"record":{"id":"3f4f199270bc5ea3","repo":"dotnet/AspNetCore.Docs","slug":"skip-3","errorCode":null,"errorMessage":"Skip 3","messagePattern":"Skip 3","errorType":"exception","errorClass":"OperationCanceledException","httpStatus":null,"severity":"warning","filePath":"aspnetcore/blazor/fundamentals/logging.md","lineNumber":171,"sourceCode":"> :::no-loc text=\"Someone clicked me at 04/21/2022 12:15:57!\":::\n\n## Client-side log exception parameters\n\n[Log exception parameters](xref:fundamentals/logging/index#log-exceptions) are supported.\n\nThe following example shows how to use log exception parameters with the `Counter` component of an app created from a Blazor project template.\n\nIn the `IncrementCount` method of the app's `Counter` component (`Counter.razor`):\n\n```csharp\ncurrentCount++;\n\ntry\n{\n    if (currentCount == 3)\n    {\n        currentCount = 4;\n        throw new OperationCanceledException(\"Skip 3\");\n    }\n}\ncatch (Exception ex)\n{\n    logger.LogWarning(ex, \"Exception (currentCount: {Count})!\", currentCount);\n}\n```\n\nDeveloper tools console output:\n\n> :::no-loc text=\"warn: BlazorSample.Pages.Counter[0]\":::  \n> :::no-loc text=\"Exception (currentCount: 4)!\":::  \n> :::no-loc text=\"System.OperationCanceledException: Skip 3\":::  \n> :::no-loc text=\"at BlazorSample.Pages.Counter.IncrementCount() in C:\\Users\\Alaba\\Desktop\\BlazorSample\\Pages\\Counter.razor:line 28\":::\n\n## Client-side filter function\n\n[Filter functions](xref:fundamentals/logging/index#filter-function) are supported.","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/blazor/fundamentals/logging.md#L153-L189","documentation":"Intentionally-thrown OperationCanceledException(\"Skip 3\") in the Counter sample to demonstrate logging exception parameters. After incrementing currentCount to 3 it is forced to 4 and the exception is thrown, then caught and logged via logger.LogWarning(ex, \"...{Count}...\", currentCount) so the developer-console output shows currentCount: 4. Teaching code for structured logging of exceptions.","triggerScenarios":"Clicking increment until currentCount equals 3; the sample sets it to 4 and throws. The catch logs the warning with the parameterized count.","commonSituations":"Running the logging sample to observe warn-level console output; copying it to learn ILogger usage with exception and format arguments.","solutions":["Recognize this is illustrative; remove the artificial throw for real counter logic.","If demonstrating logging, keep the throw but ensure the catch uses the correct log level and parameter placeholders.","Verify ILogger is injected (the catch must not throw NullReferenceException if logger is null)."],"exampleFix":"// before\nif (currentCount == 3)\n{\n    currentCount = 4;\n    throw new OperationCanceledException(\"Skip 3\");\n}\n\n// after — log a real skip condition without throwing\ncurrentCount++;\nif (currentCount == 3)\n{\n    currentCount = 4;\n    logger.LogWarning(\"Skipped count of 3; currentCount now {Count}.\", currentCount);\n}","handlingStrategy":"try-catch","validationCode":"currentCount++;\nif (currentCount == 3) { currentCount = 4; /* log instead of throw */ }","typeGuard":null,"tryCatchPattern":"try { /* increment */ }\ncatch (Exception ex) when (ex is OperationCanceledException)\n{\n    logger.LogWarning(ex, \"Skipped count (currentCount: {Count}).\", currentCount);\n}","preventionTips":["Inject ILogger and ensure it is non-null before logging.","Use structured logging placeholders ({Count}), not string interpolation.","Avoid throws for normal control flow.","Pick the correct log level for the event."],"tags":["blazor","demo","logging","operationcanceledexception","structured-logging"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}