Align console logging example with ASP.NET Core logging example#4855
Align console logging example with ASP.NET Core logging example#4855utpilla merged 5 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4855 +/- ##
==========================================
+ Coverage 83.91% 83.95% +0.04%
==========================================
Files 293 293
Lines 12028 12021 -7
==========================================
- Hits 10093 10092 -1
+ Misses 1935 1929 -6
|
| namespace SourceGeneration; | ||
|
|
||
| public class Program | ||
| using var loggerFactory = LoggerFactory.Create(builder => |
There was a problem hiding this comment.
not something introduced in this PR, but the "using" is accidentally/un-intentionally copied as-is by a lot of users into their helper methods, and the LoggerFactory ends up disposed when the helper method exits.
There was a problem hiding this comment.
What options do we have and which one do you like?
- Remove
using, leave Dispose to GC finalizer (if there is a finalizer). - Add a comment to tell the user.
- Remove
using, add an explicitDisposeat the end of the application.
I'll give 1) -100, 2) +2, 3) +1
There was a problem hiding this comment.
A combination of 2, 3 i.e remove using, and add explicit Dispose at the end. And comments saying
- Loggerfactory must be kept active for the logging to work. (to warn about disposing too early)
- Loggerfactory must be disposed at the end/shutdown to make sure any in-buffers telemetry is pushed out as well. (to warn about not disposing at all)
Not something to be fixed for this PR, as this issue is there for other getting-started docs as well
Essentially stealing good stuff from #4821.