-
-
Notifications
You must be signed in to change notification settings - Fork 376
feat(ErrorLogger): check EnableErrorLogger parameter #7483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR updates the ErrorLogger component so that it conditionally provides the error-logging cascading context only when error logging is enabled, and tightens logging behavior in the BootstrapBlazorErrorBoundary to only log when ILogger is enabled for error level. Sequence diagram for conditional error logging and renderingsequenceDiagram
actor User
participant ErrorLogger
participant CascadingValue_IErrorLogger_ as CascadingValue_IErrorLogger
participant ChildComponent
participant BootstrapBlazorErrorBoundary as ErrorBoundary
participant ILogger as Logger
User->>ErrorLogger: Render
activate ErrorLogger
alt EnableErrorLogger is true
ErrorLogger->>CascadingValue_IErrorLogger: Provide IErrorLogger context
CascadingValue_IErrorLogger->>ErrorBoundary: RenderError (wrap ChildContent)
activate ErrorBoundary
User->>ChildComponent: Interact (may cause exception)
ChildComponent-->>ErrorBoundary: Exception thrown
ErrorBoundary->>ErrorBoundary: OnErrorAsync(exception)
alt EnableILogger and Logger.IsEnabled(Error)
ErrorBoundary->>Logger: LogError(exception, uri)
else logging disabled
ErrorBoundary-->>Logger: No call
end
deactivate ErrorBoundary
else EnableErrorLogger is false
ErrorLogger->>ChildComponent: Render ChildContent directly
User->>ChildComponent: Interact (exceptions not logged here)
end
deactivate ErrorLogger
Class diagram for updated ErrorLogger and BootstrapBlazorErrorBoundary behaviorclassDiagram
class IErrorLogger
class ErrorLogger {
bool EnableErrorLogger
RenderFragment ChildContent
RenderFragment ErrorContent
bool EnableILogger
BootstrapBlazorErrorBoundary _errorBoundary
+BuildRenderTree(RenderTreeBuilder builder) void
-RenderError RenderFragment
}
class CascadingValue_IErrorLogger_ {
IErrorLogger Value
bool IsFixed
RenderFragment ChildContent
}
class BootstrapBlazorErrorBoundary {
bool EnableILogger
ILogger Logger
NavigationManager NavigationManager
RenderFragment ErrorContent
RenderFragment ChildContent
+OnErrorAsync(Exception exception) Task
}
ErrorLogger ..|> IErrorLogger
ErrorLogger --> CascadingValue_IErrorLogger_ : wraps
ErrorLogger --> BootstrapBlazorErrorBoundary : creates
BootstrapBlazorErrorBoundary --> ILogger : uses
BootstrapBlazorErrorBoundary --> NavigationManager : uses
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7483 +/- ##
===========================================
- Coverage 100.00% 99.98% -0.02%
===========================================
Files 749 749
Lines 32936 32941 +5
Branches 4576 4576
===========================================
+ Hits 32936 32937 +1
- Misses 0 3 +3
- Partials 0 1 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the ErrorLogger component to properly respect the EnableErrorLogger parameter by conditionally rendering the error handling infrastructure only when enabled, and adds a performance optimization to check log level before logging.
- Refactored
BuildRenderTreeto conditionally render error handling based onEnableErrorLogger - Fixed component reference capture index from 5 to 7 (correcting a bug)
- Added
Logger.IsEnabled(LogLevel.Error)check before logging for performance optimization
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/BootstrapBlazor/Components/ErrorLogger/ErrorLogger.cs | Refactored BuildRenderTree to check EnableErrorLogger and conditionally wrap content in CascadingValue with error boundary; removed RenderContent property; fixed component reference capture index |
| src/BootstrapBlazor/Components/ErrorLogger/BootstrapBlazorErrorBoundary.cs | Added Logger.IsEnabled check before logging to avoid unnecessary logging overhead |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (EnableErrorLogger) | ||
| { | ||
| builder.OpenComponent<CascadingValue<IErrorLogger>>(0); | ||
| builder.AddAttribute(1, nameof(CascadingValue<>.Value), this); | ||
| builder.AddAttribute(2, nameof(CascadingValue<>.IsFixed), true); | ||
| builder.AddAttribute(3, nameof(CascadingValue<>.ChildContent), RenderError); | ||
| builder.CloseComponent(); | ||
| } | ||
| else | ||
| { | ||
| builder.AddContent(10, ChildContent); | ||
| } |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refactored BuildRenderTree method introduces new conditional logic where EnableErrorLogger false directly renders ChildContent without the CascadingValue wrapper. However, there are no tests in ErrorLoggerTest.cs that verify this specific behavior. Consider adding a test that verifies when EnableErrorLogger is false, the CascadingValue is not created and ChildContent is rendered directly.
| if (EnableErrorLogger) | ||
| { | ||
| builder.OpenComponent<CascadingValue<IErrorLogger>>(0); | ||
| builder.AddAttribute(1, nameof(CascadingValue<>.Value), this); | ||
| builder.AddAttribute(2, nameof(CascadingValue<>.IsFixed), true); | ||
| builder.AddAttribute(3, nameof(CascadingValue<>.ChildContent), RenderError); | ||
| builder.CloseComponent(); | ||
| } | ||
| else | ||
| { | ||
| builder.AddContent(10, ChildContent); | ||
| } |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When EnableErrorLogger is false, the _errorBoundary field will not be initialized (remains null). While the current call site in BootstrapComponentBase checks EnableErrorLogger before calling HandlerExceptionAsync (line 136), the method itself is public and part of the IErrorLogger interface. Consider adding a null check or EnableErrorLogger guard within HandlerExceptionAsync to make it safer for direct calls and prevent potential NullReferenceException if the method is called when EnableErrorLogger is false.
Link issues
fixes #7482
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Gate the ErrorLogger cascading component and error boundary rendering on the EnableErrorLogger flag and tighten error logging conditions.
Bug Fixes:
Enhancements: