Skip to content

Switch to Microsoft.Extensions.Logging#4247

Merged
roji merged 1 commit intonpgsql:mainfrom
roji:Logging
Jan 1, 2022
Merged

Switch to Microsoft.Extensions.Logging#4247
roji merged 1 commit intonpgsql:mainfrom
roji:Logging

Conversation

@roji
Copy link
Member

@roji roji commented Dec 28, 2021

This is a first phase of work on our logging implementation - it switches us to use Microsoft.Extensions.Logging.

  • Note that user setup is the same - an ILoggerFactory must be statically injected before any Npgsql API are used. I have some ideas on making things more DI-compatible (possibly via DbDataSource), but that's out of scope for now.
  • The command logging (on execution) is a bit tricky - pay special attention to that.
  • There's still quite a bit of messiness, especially around which events use the new source-generation method, and which are ad-hoc logging events. We should probably revisit later for some more cleanup (it was already a lot of work :)).

Closes #2103

@roji roji enabled auto-merge (squash) January 1, 2022 20:43
@roji roji merged commit 0f45fb1 into npgsql:main Jan 1, 2022
@roji roji deleted the Logging branch January 1, 2022 21:11
if (process.ExitCode != 0)
{
Log.Debug($"klist exited with code {process.ExitCode}: {process.StandardError.ReadToEnd()}");
Logger.LogDebug($"klist exited with code {process.ExitCode}: {process.StandardError.ReadToEnd()}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed several strings using interpolating formatting. Was that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - opened #4277 to track cleaning this up.

Debug.Assert(State != ConnectorState.Ready, "Forgot to start a user action...");

Log.Trace("Executing internal pregenerated command", Id);
Logger.LogTrace("Executing internal pregenerated command", Id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some strings in this PR have arguments but not corresponding parameter in the template.

Copy link
Member Author

@roji roji Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's intentional - the idea is to report certain structured fields but without necessarily including them in the message (see dotnet/runtime#35995), since it's not always appropriate to pack all possible data into that string. The connection ID is a good example - I'm not sure we should overload textual output for every single message with the ID (because in many/most cases that doesn't matter), but the data should be there in case someone wants to filter by a specific connection id, for example.

Any thoughts on this? Do you think it's problematic practice?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, wanted to check if it was intentional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace our custom logging with Microsoft.Extensions.Logging

3 participants