-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Added name for EventId in logs #11379
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
Conversation
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.
Looks good, but we should remove the nameof
s. Even though they reference LoggerEventIds
, we still want to reduce the possibility of unintentionally changing these names without realizing.
@@ -172,7 +172,7 @@ private void LogRequestStarting(HttpContext httpContext) | |||
// IsEnabled is checked in the caller, so if we are here just log | |||
_logger.Log( | |||
logLevel: LogLevel.Information, | |||
eventId: LoggerEventIds.RequestStarting, | |||
eventId: new EventId(LoggerEventIds.RequestStarting, nameof(LoggerEventIds.RequestStarting)), |
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.
I would avoid nameof
here. Even though we don't intent to change this, if we did ever change the name of the property it would break consumers. We started using nameof
originally but decided it was better to just use string constants. The goal of nameof
is to ensure that when you rename the target of the nameof
expression, your reference is updated which is actually not what we want here.
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.
I hadn't thought about it that way at first, but I can see your point. This should be corrected in the latest commit.
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.
Looks good. It's unfortunate that some of these have 0
as the numeric event ID, but changing that is a breaking change and I don't think we want to do that.
Build failures look unrelated. I'll restart. |
This comment was made automatically. If there is a problem contact [email protected]. I've triaged the above build. I've created/commented on the following issue(s) |
@anurse is there any chance that this could merge into asp.net core 3? |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
@mikeo52 Can you resolve the conflict? |
FYI this is targeting the wrong branch for v3.x. It would need to be rebased and retargeted to @Pilchie bar check for 3.x? Incremental diagnostic improvements. |
It's very late for 3.0, but does fit into a diagnosability theme for 3.1. |
Oof, this got lost in some of the push to get 3.0 out the door. I'm going to respin the builds and see where we land. There is also a conflict to resolve. |
@mikeo52 are you up to try rebasing this on |
Okay that makes absolutely no sense to me, but whatever. On this PR's merge conflicts screen I can edit the merge to my repo via the browser and resolve the conflicts, but if I use the git command line I constantly run into the other issue. |
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 few small things. Looking good though. Thanks for resolving the conflict!
logLevel: LogLevel.Warning, | ||
formatString: Resources.FileSystem_EphemeralKeysLocationInContainer); | ||
|
||
_usingRegistryAsKeyRepositoryWithDPAPI = LoggerMessage.Define<string>( | ||
eventId: 0, | ||
eventId: new EventId(0, "UsingRegistryAsKeyRepositoryWithDPAPI"), |
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.
Given that this is 5.0, I feel OK putting proper EventIds in place here.
For simplicity, I think it's OK to just use the same EventId sequence as the previous ones, even if these messages are used with different loggers. Thoughts @davidfowl ? It makes it easy to keep them consistent and EventIds are arbitrary anyway.
@mikeo52 can you continue the EventId number sequence with these last few events? (61, 62, 63...)
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.
@anurse should be good to go with the latest commit.
@@ -175,7 +175,7 @@ private void LogRequestStarting(HostingApplication.Context context) | |||
|
|||
_logger.Log( | |||
logLevel: LogLevel.Information, | |||
eventId: LoggerEventIds.RequestStarting, | |||
eventId: new EventId(LoggerEventIds.RequestStarting, "RequestStarting"), |
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.
I think you could go to LoggerEventIds
and change them from ints to EventId
structs (you'd also have to change from const
to static readonly
fields but it's an internal type so I think that's OK. Could you give that a look @mikeo52 ?
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.
@anurse I think I've got the change you were after made in this regard. Take a look and let me know. I'm having trouble building locally since my local setup's a little borked, so my apologies if the extra commits are making noise.
@@ -22,15 +22,15 @@ public static IDisposable RequestScope(this ILogger logger, HttpContext httpCont | |||
public static void ApplicationError(this ILogger logger, Exception exception) | |||
{ | |||
logger.ApplicationError( | |||
eventId: LoggerEventIds.ApplicationStartupException, | |||
eventId: new EventId(LoggerEventIds.ApplicationStartupException, "ApplicationStartupException"), |
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.
Same here, we should try to just replace the LoggerEventIds
constants themselves.
Co-Authored-By: Andrew Stanton-Nurse <[email protected]>
Thanks |
@Tratcher Is it possible to also merge this to 3.1? |
No, 3.1 is only taking critical patches now. |
I see, thanks. |
Added name for EventId in Hosting, DataProtection, EntityFrameworkCore. #6381