@@ -45,9 +45,17 @@ Chosen option: **Consolidate logging providers**.
45
45
46
46
Given long-term plans to adopt a more flexible shared (hosting extensions) library that can be used
47
47
across services either as a project (server monolith) reference or NuGet package (and as a reference
48
- architecture), using Serilog as a way to extend native logging capabilities is beneficial. Details
49
- around how Serilog is implemented along with its advanced inputs and outputs can be extracted away
50
- into the shared library and driven at consuming applications via configuration.
48
+ architecture), using ` Microsoft.Extensions.Logging ` as the core way to do logging is beneficial. The
49
+ out-of-the-box defaults are generally good enough for local and self-hosted usage. Our shared
50
+ library will be able to have automatic defaults for our cloud usage though, namely using JSON
51
+ logging along with including scopes. It also gives us a built-in way to be able to override any of
52
+ these details through any of our configuration providers.
53
+
54
+ We will continue to offer file based logging through Serilog but will be able to reduce our NuGet
55
+ packages to only ` Serilog.Extensions.Logging.File ` . In an effort to reduce our own upkeep and allow
56
+ maximal customization we will be deprecating the log settings in ` GlobalSettings ` ; instead we will
57
+ refer to [ ` Serilog ` documentation] [ serilogconfig ] to offer both more options and more standard
58
+ naming.
51
59
52
60
### Positive Consequences
53
61
@@ -56,6 +64,9 @@ into the shared library and driven at consuming applications via configuration.
56
64
- Elimination of several third-party dependencies and their maintenance, as well as global settings.
57
65
- No new dependencies that are merely aligned with the Bitwarden-specific cloud and its service
58
66
providers.
67
+ - Allow self-host customers to configure the console log format.
68
+ - Not require any new configuration for our cloud that is currently using
69
+ ` Microsoft.Extensions.Logging ` .
59
70
60
71
### Negative Consequences
61
72
@@ -72,13 +83,16 @@ be removed:
72
83
- Sentry
73
84
- Syslog
74
85
75
- The remaining sinks -- core functionality of Serilog -- will continue to be supported:
86
+ The ` File ` sink will continue to be supported with the following configuration layout :
76
87
77
- - Console
78
- - File
79
-
80
- While the Serilog [ console sink] [ serilogconsole ] is currently an implicit dependency with what's
81
- provided for ASP.NET Core, it will be explicitly referenced.
88
+ ``` json
89
+ {
90
+ "Logging" : {
91
+ "PathFormat" : " logs/{Date}.txt" ,
92
+ "FileSizeLimitBytes" : 4096
93
+ }
94
+ }
95
+ ```
82
96
83
97
Solutions exist for users to shift processing of logs for the removed sinks to standard output or
84
98
file and retain their integration. Admin Portal users can similarly continue to use CosmosDb for log
@@ -87,34 +101,36 @@ should in essentially all cases be able to receive and process standard output l
87
101
88
102
Cloud installations -- including Bitwarden's own -- will shift to configuration via environment
89
103
variables or otherwise to utilize structured standard output logs for processing explicitly with
90
- [ Serilog configuration] [ serilogconfig ] e.g.:
104
+ [ ` Microsoft.Extensions.Logging ` configuration] [ melconfig ] this will also allow online updates if the
105
+ configuration is done through a provider that supports change detection e.g.:
91
106
92
107
``` json
93
108
{
94
- "Serilog" : {
95
- "Using" : [" Serilog.Sinks.Console" ],
96
- "MinimumLevel" : " Verbose" ,
97
- "WriteTo" : [{ "Name" : " Console" }],
98
- "Enrich" : [" FromLogContext" ],
99
- "Properties" : {
100
- "Project" : " BitwardenProjectName"
109
+ "Logging" : {
110
+ "LogLevel" : {
111
+ "Default" : " Information"
112
+ },
113
+ "Console" : {
114
+ "FormatterName" : " json" ,
115
+ "FormatterOptions" : {
116
+ "SingleLine" : true ,
117
+ "IncludeScopes" : true ,
118
+ "TimestampFormat" : " HH:mm:ss " ,
119
+ "UseUtcTimestamp" : true ,
120
+ "JsonWriterOptions" : {
121
+ "Indented" : true
122
+ }
123
+ }
101
124
}
102
125
}
103
126
}
104
127
```
105
128
106
- This will allow better usage of ` appsettings.json ` and a richer developer experience. Existing
107
- built-in [ .NET Core logging] [ netcorelogging ] will continue to be available if desired, but the
108
- recommendation will be to move to a Serilog configuration.
109
-
110
129
Code cleanup will be performed around Serilog usage, such as:
111
130
112
131
- Removal of overuse of inclusion predicates that complicate (or sometimes block) effective log
113
132
output, for example in the uses of ` AddSerilog ` in place today at each consuming application.
114
- - Alignment with .NET Core and Serilog best practices on [ initialization] [ seriloginit ] and usage of
115
- Serilog itself.
116
- - Improvements in logging initialization reliability and working with configuration issues, as well
117
- as more resilient tear-down when a component stops / ends.
133
+ - Reading file sink config from the ` Logging ` configuration section.
118
134
- Removal of the above-deprecated sinks, in the final release of the support window.
119
135
120
136
Logging functionality will be moved to a new shared library -- separate from the core project -- as
@@ -125,7 +141,7 @@ benefits.
125
141
[ serilog ] : https://serilog.net/
126
142
[ dd ] : https://www.datadoghq.com/
127
143
[ ddsink ] : https://www.nuget.org/packages/serilog.sinks.datadog.logs
128
- [ serilogconsole ] : https://www.nuget.org/packages/serilog.sinks.console
129
- [ serilogconfig ] : https://www.nuget.org/packages/Serilog.Settings.Configuration/
130
- [ netcorelogging ] : https://learn.microsoft.com/en-us/dotnet/core/extensions/logging
131
- [ seriloginit ] : https://github. com/serilog/serilog-aspnetcore#two-stage-initialization
144
+ [ serilogconfig ] :
145
+ https://github.com/serilog/serilog-extensions-logging-file?tab=readme-ov-file#appsettingsjson-configuration
146
+ [ melconfig ] :
147
+ https://learn.microsoft. com/en-us/dotnet/core/extensions/logging?tabs=command-line#configure-logging
0 commit comments