Skip to content
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

Add log event name for Identity #16879

Merged
merged 4 commits into from
Jan 26, 2021
Merged

Conversation

Kahbazi
Copy link
Member

@Kahbazi Kahbazi commented Nov 6, 2019

  • Added event id and name for logs.
  • change Some of event ids that were 0.
  • make logs structured in Identity/ApiAuthorization.IdentityServer

Addresses #6381

@Pilchie Pilchie added the area-identity Includes: Identity and providers label Nov 7, 2019
@Kahbazi Kahbazi requested a review from HaoK February 20, 2020 12:46
@@ -714,7 +714,7 @@ public virtual async Task<bool> CheckPasswordAsync(TUser user, string password)
var success = result != PasswordVerificationResult.Failed;
if (!success)
{
Logger.LogWarning(0, "Invalid password for user {userId}.", await GetUserIdAsync(user));
Logger.LogWarning(LoggerEventIds.InvalidPassword, "Invalid password for user {userId}.", await GetUserIdAsync(user));
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we can just change log ids like this can we? @ajcvickers @blowdart is there some kind of guarantee with event ids being stable generally in logs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, they are expected to remain stable.

Copy link
Member

Choose a reason for hiding this comment

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

@Kahbazi so I guess if you are going to move to a variable for these, you are going to have to ensure that the order/values match.

@HaoK
Copy link
Member

HaoK commented Jun 29, 2020

Closing since this PR changes event ids

@HaoK HaoK closed this Jun 29, 2020
@Kahbazi
Copy link
Member Author

Kahbazi commented Jun 30, 2020

@HaoK I forgot about this PR! I will change back the event ids. Can I continue on this PR or should I create a new one?

@HaoK
Copy link
Member

HaoK commented Jun 30, 2020

You can continue using this one sure!

@@ -291,7 +291,7 @@ public virtual async Task<TUser> ValidateTwoFactorSecurityStampAsync(ClaimsPrinc
{
return user;
}
Logger.LogDebug(5, "Failed to validate a security stamp.");
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we have different event ids for the same message, 4 and 5 due to different methods

Copy link
Member

Choose a reason for hiding this comment

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

@Kahbazi I think its fine to introduce the logging extensions to the API which wasn't currently using event ids, but it doesn't look like its worth the potential regression in modifying the event ids for the sign in manager/existing apis. Unless you want to introduce a line by line method, so maybe lets just revert/delete LogginExtensions, but keep the LoggerEventIds changes

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to be consentience for each log. Should I delete LogginExtensions completely and add event id to each logs?
Or add another method to LogginExtensions for invalid security stamp?

Copy link
Member

Choose a reason for hiding this comment

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

Right maybe the safest way to do it is https://github.com/dotnet/aspnetcore/pull/16879/files#diff-7d0bb5dd924f2d3e3de48da228cfbd19 so introduce a new file that's just the ids,, so no LoggingExtensions class like you said

@Kahbazi Kahbazi force-pushed the kahbazi/identityEventLog branch from c099cd1 to fd4714c Compare October 8, 2020 12:22
@@ -138,7 +138,7 @@ public override async Task<IActionResult> OnPostAsync(string returnUrl = null)

if (result.Succeeded)
{
_logger.LogInformation("User created a new account with password.");
_logger.LogInformation(LoggerEventIds.UserCreated, "User created a new account with password.");
Copy link
Member

Choose a reason for hiding this comment

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

@blowdart any concerns with logging using an event id in the library and scaffolding still logging like before?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes actually. If once you scaffold your log event ids change that's a bad thing. They need to match.

Copy link
Member

Choose a reason for hiding this comment

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

So are you saying you prefer the UI just doesn't specify event ids? It seems bad to scaffold out a new file just to add event ids

Copy link
Member

Choose a reason for hiding this comment

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

@Kahbazi I chatted with @blowdart offline and looks like this is pretty much ready to go except for one minor tweak, can you make the LoggerEventIds class public that the Identity UI code uses, since we want to be able to reference that in the scaffolded code. When we port these changes to the scaffolded pages

@Tratcher Tratcher added the community-contribution Indicates that the PR has been added by a community member label Nov 19, 2020
@HaoK
Copy link
Member

HaoK commented Nov 20, 2020

Thanks for making it public @Kahbazi unfortunately you will need to add doccomments for these now as well :/

@Kahbazi
Copy link
Member Author

Kahbazi commented Nov 21, 2020

Thanks for making it public @Kahbazi unfortunately you will need to add doccomments for these now as well :/

Do I need to add documents for just the class or include each EventId? If so could you please provide a sample so I can follow the sentence structure.

@HaoK
Copy link
Member

HaoK commented Dec 10, 2020

Sorry for the delay getting back to you @Kahbazi you will need to document public/protected just like everything else for apis, I don't think you need to go into much detail, for example: "Static class that exposes logging event ids." for the class summary, then something like "Event id when a user is created by an external provider." for UserCreatedByExternalProvider as an example.

@HaoK
Copy link
Member

HaoK commented Jan 11, 2021

Hey @Kahbazi thanks for grinding through this, do you think you can try applying the relevant steps here to fix the issues with the public surface area? #24347 (comment)

With step 7 being the only thing you really need to do, fixing the new api stuff I think, since you don't need to add the baseline files

Choose “Add Blah to public API” / “Fix all occurrences in … Solution”
Click Apply

Let me know if that doesn't work, I can take over the PR and merge it into one of my branches for the final step if the public api baselines don't update for you correctly

@Kahbazi Kahbazi force-pushed the kahbazi/identityEventLog branch from 6063ad1 to cd53b2e Compare January 15, 2021 21:57
Base automatically changed from master to main January 22, 2021 01:32
@HaoK
Copy link
Member

HaoK commented Jan 26, 2021

Thanks for sticking with this and getting this done @Kahbazi !

@HaoK HaoK merged commit 8822621 into dotnet:main Jan 26, 2021
@Kahbazi Kahbazi deleted the kahbazi/identityEventLog branch January 26, 2021 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-identity Includes: Identity and providers community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants