This repository was archived by the owner on Nov 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
WIP: provide guidance on logging frameworks #130
Open
gverstraete
wants to merge
2
commits into
Codit:master
Choose a base branch
from
gverstraete:5-provide-guidance-on-logging-frameworks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Logging Guidance | ||
Logging consists of several parts that should all be considered on design & development time. | ||
|
||
- How should you structure your logs? | ||
- How should you aggregate your logs? | ||
- What are usefull logs (in each environment)? | ||
- More technical: what framework should you use? | ||
|
||
## Logging principals | ||
Logging should be crystal clear and should give a direct insight in how the application is setup and should give a logical overview on what is happening. | ||
|
||
In order to do this, it is mandatory to use a `correlationId`. A correlationId is an id which groups seperate logs together to a group. In the case of an api, each request will be one `correlationId`. | ||
|
||
If the sink you are sending to supports this behavior, you can also create tree's in this correlation to distinct even more and make more clear what is actually happening in your code. | ||
|
||
There are different types of logs that can be made, for API's these are the most important ones: | ||
|
||
| Log Type | Description | | ||
| -------- | ----------- | | ||
| Request | Logging the incoming request, including response code, execution time etc... | | ||
| Trace | Traces consists of usefull information in different verbosity levels (explained later) for a functional understanding of the API | | ||
| Exception | On exception the details of the exceptions should be logged | | ||
| Dependency | Tracking external dependencies like backend api's / database calls etc, with response code, execution time etc... | | ||
|
||
All of this combined will give you a good understanding of how your application reacts in certain scenario's. It will be able to give you a result of load on the API, to detect and fix possible issues quickly and to give operations/support the ability to track the important measurements in a dashboard. | ||
|
||
While doing so, try to avoid string concatenation as this might make your application less monitorable and make search queries more difficult. | ||
|
||
The logs mentioned over here should be a combination of functional and technical logs. Every log should have an added value to functional and technical people, to operations & to developers. | ||
|
||
In the end it might be good to have all these logs in one resultset on an acceptance environment, but it might not be needed on a production environment. | ||
That's why every log should have a `LogLevel`. The loglevel should be defined on every log. On every application there should a minimal loglevel be defined by configuration. | ||
|
||
Trace logs can be set to different LogLevels. | ||
List of log level from most detailed to most general. | ||
1. Verbose | ||
1. Info | ||
1. Warning | ||
1. Error | ||
1. Off | ||
|
||
ref: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.tracelevel?view=netcore-2.2 | ||
|
||
Generally, Loglevels can be set on Application level. The values applicable here are: | ||
1. Trace | ||
1. Debug | ||
1. Warning | ||
1. Error | ||
1. Critical | ||
1. None | ||
|
||
ref: https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loglevel?view=aspnetcore-2.2 | ||
|
||
|
||
# Logging sinks | ||
By default, a console log should be added. | ||
|
||
On Azure projects, by default, there should also be an output to Application Insights. | ||
|
||
# Logging frameworks | ||
There are different ways to log your logs in C#. | ||
|
||
- If there are Application Insights specifics, such as: | ||
- Dependency logging | ||
- Custom Dimension logging | ||
- Tree correlations | ||
|
||
Use the direct Application Insights logging library. | ||
|
||
- If you don't have this requirement there are 2 possible ways to go for. [Microsoft.Extensions.Logging.ILogger](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.ilogger?view=aspnetcore-2.2) or [Serilog](https://serilog.net/) |
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.
Uh oh!
There was an error while loading. Please reload this page.