API surface gaps: DPanic, Log overloads, structured timing, Conditional tests#27
Merged
API surface gaps: DPanic, Log overloads, structured timing, Conditional tests#27
Conversation
Adds the four missing exception overloads to the Log static class, matching the existing pattern used by Error and Critical. Trace and Debug overloads carry [Conditional] attributes consistent with their non-exception counterparts. Defines LOGSMITH_TRACE/LOGSMITH_DEBUG in the test project to enable testing conditional static methods.
DPanic dispatches at Error level, then conditionally throws InvalidOperationException when ThrowOnDPanic is enabled via LogConfigBuilder. Provides string-based and handler-based overloads for dev-time fail-fast patterns.
TimingOperation now emits both Utf8Message (human-readable text) and Utf8Json (structured properties) via ThreadBuffer, matching the dual-output pattern used by log handlers. JSON includes operation, outcome, elapsed_ms, and step (for TimeStep calls).
Verifies that Log.Trace and Log.Debug call sites (including exception overloads) are stripped from emitted IL when LOGSMITH_TRACE / LOGSMITH_DEBUG symbols are absent. Uses Roslyn in-memory compilation and PEReader to inspect MemberReferences in the emitted assembly. Also verifies Information/Warning/Error/Critical are never stripped.
DPanic throws regardless of level filtering because it is a correctness guard, not a log-level concern. Added doc comment clarifying this behavior and a test verifying the throw fires even when MinimumLevel is above Error.
DJGosnell
added a commit
that referenced
this pull request
Apr 5, 2026
…al tests (#27) * Add exception overloads for Log.Trace, Debug, Information, Warning Adds the four missing exception overloads to the Log static class, matching the existing pattern used by Error and Critical. Trace and Debug overloads carry [Conditional] attributes consistent with their non-exception counterparts. Defines LOGSMITH_TRACE/LOGSMITH_DEBUG in the test project to enable testing conditional static methods. * Add DPanic method to ILogger with configurable throw behavior DPanic dispatches at Error level, then conditionally throws InvalidOperationException when ThrowOnDPanic is enabled via LogConfigBuilder. Provides string-based and handler-based overloads for dev-time fail-fast patterns. * Add structured JSON output to TimingOperation TimingOperation now emits both Utf8Message (human-readable text) and Utf8Json (structured properties) via ThreadBuffer, matching the dual-output pattern used by log handlers. JSON includes operation, outcome, elapsed_ms, and step (for TimeStep calls). * Add automated [Conditional] stripping validation tests Verifies that Log.Trace and Log.Debug call sites (including exception overloads) are stripped from emitted IL when LOGSMITH_TRACE / LOGSMITH_DEBUG symbols are absent. Uses Roslyn in-memory compilation and PEReader to inspect MemberReferences in the emitted assembly. Also verifies Information/Warning/Error/Critical are never stripped. * Document DPanic throw-vs-level semantics and add coverage test DPanic throws regardless of level filtering because it is a correctness guard, not a log-level concern. Added doc comment clarifying this behavior and a test verifying the throw fires even when MinimumLevel is above Error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reason for Change
Several planned API surface items were deferred during the ILogger rework. These four additive enhancements fill the remaining gaps.
Impact
[Conditional]attributesDPanicdefault interface methods (string + handler, with/without exception)[Conditional]stripping validationThrowOnDPanicproperty onLogConfigBuilder(defaults to false)Plan items implemented as specified
ThrowOnDPanicconfig flagDeviations from plan implemented
ThrowOnDPanic) instead of#if DEBUG—#if DEBUGevaluates at library compile time and is useless for NuGet consumersGaps in original plan implemented
Migration Steps
None — all changes are additive with safe defaults.
Performance Considerations
Encoding.UTF8.GetBytes(string)— consistent with handler internals, zero-allocation via thread-local poolingDispatchString/DispatchHandlerpath plus a single bool checkSecurity Considerations
None.
Breaking Changes
LogConfigconstructor gainsthrowOnDPanicparameter (internal class, no public impact)🤖 Generated with Claude Code