-
Notifications
You must be signed in to change notification settings - Fork 778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Align console logging example with ASP.NET Core logging example #4855
Align console logging example with ASP.NET Core logging example #4855
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 explicitDispose
at the end of the application.
I'll give 1) -100, 2) +2, 3) +1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.