Repository navigation
Log every use case, unexpected errors and requests once each - #40
Merged
Merged
Conversation
Contributor
Build Pipeline✅ Ready to merge. Every stage passed.
Commit |
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
Until now nothing we wrote logged anything, and the one log line per request was wrong for errors. This gives each request a clear trail, the same as CleanMinimalApi #66.
LoggingBehaviourwraps every use case and logs how it ended, atInformation, with the request name and its time in milliseconds: handled, failed validation (with the property names, never the values) or found nothing. It's registered beforeValidationBehaviour, so it sees validation failures too. The messages are[LoggerMessage]source-generated, and the time comes fromTimeProvider.ApplicationExceptionHandlernow logs anything it turns into a500asError, with the exception. Handling an exception stops ASP.NET Core logging it, so before this a crash left only a status code behind.400and404as a500, stack trace and all. Now each request is logged once with the status the client got.Informationis the default level, andappsettings.local.jsonlowers it toDebug.TimeProvider.Systemis registered withTryAddSingletonin bothAddApplicationandAddInfrastructure, so each layer works on its own without registering the clock twice.FakeLogger(Microsoft.Extensions.Diagnostics.Testing, MIT) checks the messages in the behaviour and handler tests.serilog,mediator,time-provider,errors-and-exceptions,unit-testsandapi-conventionsskills describe all of this.