@@ -107,6 +107,21 @@ Here is the rule of thumb:
107
107
Minutes - Console Application] ( ./getting-started-console/README.md ) tutorial
108
108
to learn more.
109
109
110
+ :heavy_check_mark : You should use dot-separated
111
+ [ UpperCamelCase] ( https://en.wikipedia.org/wiki/Camel_case ) as the log category
112
+ name, which makes it convenient to [ filter logs] ( #log-filtering ) . A common
113
+ practice is to use fully qualified class name, and if further categorization is
114
+ desired, append a subcategory name. Refer to the [ .NET official
115
+ document] ( https://learn.microsoft.com/dotnet/core/extensions/logging#log-category )
116
+ to learn more.
117
+
118
+ ``` csharp
119
+ loggerFactory .CreateLogger <MyClass >(); // this is equivalent to CreateLogger("MyProduct.MyLibrary.MyClass")
120
+ loggerFactory .CreateLogger (" MyProduct.MyLibrary.MyClass" ); // use the fully qualified class name
121
+ loggerFactory .CreateLogger (" MyProduct.MyLibrary.MyClass.DatabaseOperations" ); // append a subcategory name
122
+ loggerFactory .CreateLogger (" MyProduct.MyLibrary.MyClass.FileOperations" ); // append another subcategory name
123
+ ```
124
+
110
125
:stop_sign : You should avoid creating loggers too frequently. Although loggers
111
126
are not super expensive, they still come with CPU and memory cost, and are meant
112
127
to be reused throughout the application. Refer to the [ logging performance
@@ -186,11 +201,6 @@ instances if they are created by you.
186
201
API invocation associated with the logger factory could become no-op (i.e. no
187
202
logs will be emitted).
188
203
189
- :heavy_check_mark : You should use the fully qualified class name as the log
190
- category name. Refer to the [ .NET official
191
- document] ( https://learn.microsoft.com/dotnet/core/extensions/logging#log-category )
192
- to learn more.
193
-
194
204
## Log Correlation
195
205
196
206
In OpenTelemetry, logs are automatically correlated to
0 commit comments