Skip to content

Commit

Permalink
fix: remove unnecessary logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnkwlp committed Nov 3, 2024
1 parent 1fe6384 commit 2a0ea49
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public virtual async Task<AccountExternalLoginResultDto> CallbackAsync([NotNull]
throw new AbpAuthorizationException("External login info is not available");
}

Logger.LogInformation("Received external login callback. provider: {LoginProvider}, key: {ProviderKey}", loginInfo.LoginProvider, loginInfo.ProviderKey);
Logger.LogDebug("Received external login callback. provider: {LoginProvider}, key: {ProviderKey}", loginInfo.LoginProvider, loginInfo.ProviderKey);

if (ExternalLoginOptions.Value.LogClaims)
{
Expand Down Expand Up @@ -150,8 +150,6 @@ protected virtual async Task<SignInResult> ExternalLoginSignInAsync(ExternalLogi

await LocalEventBus.PublishAsync(new UserLoginEvent(user!.Id, UserLoginEvent.ExternalLogin), onUnitOfWorkComplete: true);

Logger.LogInformation("User use provider key '{ProviderKey}' logged in with '{LoginProvider}' provider.", loginInfo.ProviderKey, loginInfo.LoginProvider);

await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
Expand Down Expand Up @@ -182,8 +180,6 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
loginDisplayName: loginInfo.ProviderDisplayName,
generateUserName: true);

Logger.LogInformation("User with name '{UserName}' created by external login with '{LoginProvider}' provider.", user.UserName, loginInfo.LoginProvider);

await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ public virtual async Task LinkLoginAsync(Guid userId)

if (await LinkUserManager.IsLinkedAsync(source, target, true))
{
Logger.LogInformation("User with id '{0}' has been link login by user id '{1}'", user.Id, source.UserId);

await ImpersonateLoginAsync(user);

await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
Expand Down Expand Up @@ -140,8 +138,6 @@ public virtual async Task DelegationLoginAsync(Guid id)
// Get the delegation source user
var user = await UserManager.GetByIdAsync(delegation.SourceUserId);

Logger.LogInformation("User with id '{0}' has been delegation login by user id '{1}'", user.Id, CurrentUser.GetId());

await ImpersonateLoginAsync(user);

await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
Expand Down Expand Up @@ -173,8 +169,6 @@ protected virtual async Task ImpersonateLoginAsync(IdentityUser user)

await SignInManager.SignInWithClaimsAsync(user, false, cliams);

Logger.LogInformation("User with id '{0}' has been impersonate login by user id '{1}'", user.Id, CurrentUser.Id);

await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.Identity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ public virtual async Task SendTfaTokenAsync(string provider)

var token = await UserManager.GenerateTwoFactorTokenAsync(user, provider);

Logger.LogInformation("User with id '{id}' has been generated new token '{token}' for provider '{provider}'.", user.Id, token, provider);

#if DEBUG
Logger.LogDebug("User with id '{id}' has been generated new token '{token}' for provider '{provider}'.", user.Id, token, provider);
#endif
await AccountTwoFactorTokenSender.SendAsync(user, provider, token);
}

Expand All @@ -290,8 +291,6 @@ public virtual async Task<AccountVerifyTokenResultDto> VerifyTfaTokenAsync(strin

var valid = await UserManager.VerifyTwoFactorTokenAsync(user, provider, input.Token);

Logger.LogInformation("User with id '{id}' use provider '{provider}' verify two-factor token '{token}' result: {valid}.", user.Id, input.Token, provider, valid);

return new AccountVerifyTokenResultDto
{
Valid = valid,
Expand Down Expand Up @@ -400,8 +399,6 @@ public virtual async Task<AccountAuthenticatorRecoveryCodesResultDto> VerifyAuth

await UserManager.GetUserIdAsync(user);

Logger.LogInformation("User with id '{id}' has enabled 2FA with an authenticator app.", user.Id);

await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.IdentityTwoFactor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ public virtual async Task SendEmailConfirmAsync()

var token = await UserManager.GenerateEmailConfirmationTokenAsync(user);

Logger.LogInformation("User with id '{id}' has been generated new token '{token}' for email confirmation'.", user.Id, token);

#if DEBUG
Logger.LogDebug("User with id '{id}' has been generated new token '{token}' for email confirmation'.", user.Id, token);
#endif
await AccountTwoFactorTokenSender.SendEmailConfirmationTokenAsync(user, token);
}

Expand All @@ -82,8 +83,6 @@ public virtual async Task UpdateEmailConfirmAsync(AccountVerifyTokenRequestDto i

var result = await UserManager.ConfirmEmailAsync(user, input.Token);

Logger.LogInformation("User with id '{Id}' valid confirm email token result: {Valid}", user.Id, result.Succeeded);

if (result.Succeeded)
{
await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
Expand Down Expand Up @@ -114,8 +113,6 @@ public virtual async Task<AccountVerifyTokenResultDto> VerifyEmailConfirmTokenAs
purpose: IdentityUserManager.ConfirmEmailTokenPurpose,
token: input.Token);

Logger.LogInformation("User with id '{Id}' valid confirm email token result: {Valid}", user.Id, valid);

return new AccountVerifyTokenResultDto
{
Valid = valid,
Expand All @@ -132,9 +129,9 @@ public virtual async Task SendChangePhoneNumberTokenAsync(AccountProfileChangePh
throw new AbpAuthorizationException();

var token = await UserManager.GenerateChangePhoneNumberTokenAsync(user, input.PhoneNumber);

Logger.LogInformation("User with id '{id}' has been generated new token '{token}' for change phone number'.", user.Id, token);

#if DEBUG
Logger.LogDebug("User with id '{id}' has been generated new token '{token}' for change phone number'.", user.Id, token);
#endif
await AccountTwoFactorTokenSender.SendChangePhoneNumberTokenAsync(user, input.PhoneNumber, token);
}

Expand All @@ -152,8 +149,6 @@ public virtual async Task<AccountVerifyTokenResultDto> VerifyChangePhoneNumberTo
token: input.Token,
phoneNumber: input.PhoneNumber);

Logger.LogInformation("User with id '{Id}' valid change phone number token result: {Valid}", user.Id, valid);

return new AccountVerifyTokenResultDto
{
Valid = valid,
Expand All @@ -174,8 +169,6 @@ public virtual async Task ChangePhoneNumberAsync(AccountProfileChangePhoneNumber
phoneNumber: input.PhoneNumber,
token: input.Token);

Logger.LogInformation("User with id '{0}' valid change phone number token result: {1}", user.Id, result.Succeeded);

if (result.Succeeded)
{
await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
Expand All @@ -202,8 +195,9 @@ public virtual async Task SendChangeEmailTokenAsync(AccountProfileChangeEmailTok

var token = await UserManager.GenerateChangeEmailTokenAsync(user, input.Email);

Logger.LogInformation("User with id '{id}' has been generated new token '{token}' for change email'.", user.Id, token);

#if DEBUG
Logger.LogDebug("User with id '{id}' has been generated new token '{token}' for change email'.", user.Id, token);
#endif
await AccountTwoFactorTokenSender.SendChangeEmailTokenAsync(user, input.Email, token);
}

Expand All @@ -218,8 +212,6 @@ public virtual async Task<AccountVerifyTokenResultDto> VerifyChangeEmailTokenAsy

var valid = await UserManager.VerifyUserTokenAsync(user, IdentityOptions.Value.Tokens.ChangeEmailTokenProvider, IdentityUserManager.GetChangeEmailTokenPurpose(input.Email), input.Token);

Logger.LogInformation("User with id '{Id}' valid change email token result: {Valid}", user.Id, valid);

return new AccountVerifyTokenResultDto
{
Valid = valid,
Expand All @@ -237,8 +229,6 @@ public virtual async Task ChangeEmailAsync(AccountProfileChangeEmailDto input)

var result = await UserManager.ChangeEmailAsync(user, input.Email, input.Token);

Logger.LogInformation("User with id '{0}' valid change email token result: {1}", user.Id, result.Succeeded);

if (result.Succeeded)
{
await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
UserName = CurrentUser.UserName,
});
}

Logger.LogInformation("User with id '{id}' has two-factor disabled", user.Id);
}

public virtual async Task EnabledAsync()
Expand All @@ -130,8 +128,6 @@ public virtual async Task EnabledAsync()
{
(await UserManager.SetTwoFactorEnabledAsync(user, true)).CheckErrors();

Logger.LogInformation("User with id '{id}' has two-factor enabled", user.Id);

if (providers.Count == 0)
{
Logger.LogWarning("User with id '{id}' does not have any valid two-factor provider but has two-factor enabled", user.Id);
Expand Down Expand Up @@ -205,8 +201,6 @@ public virtual async Task<AccountAuthenticatorRecoveryCodesResultDto> UpdateAuth

await UserManager.GetUserIdAsync(user);

Logger.LogInformation("User with id '{id}' has enabled 2FA with an authenticator app.", user.Id);

await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.IdentityTwoFactor,
Expand Down Expand Up @@ -254,8 +248,6 @@ public virtual async Task<AccountAuthenticatorRecoveryCodesResultDto> GenerateAu

var codes = await UserManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10);

Logger.LogInformation("User with id '{id}' has generated new 2FA recovery codes.", user.Id);

await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.IdentityTwoFactor,
Expand Down Expand Up @@ -299,8 +291,6 @@ public virtual async Task RemoveAuthenticatorAsync(AccountAuthenticatorCodeVerif

await UserManager.RemoveAuthenticatorAsync(user);

Logger.LogInformation("User with id '{id}' has reset their authentication app key.", user.Id);

await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.IdentityTwoFactor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public virtual async Task<IActionResult> CallbackAsync(string returnUrl = "", st
throw new AbpAuthorizationException("External login info is not available");
}

Logger.LogInformation("Received external login. provider: {LoginProvider}, key: {ProviderKey}", loginInfo.LoginProvider, loginInfo.ProviderKey);
Logger.LogDebug("Received external login. provider: {LoginProvider}, key: {ProviderKey}", loginInfo.LoginProvider, loginInfo.ProviderKey);

if (ExternalLoginOptions.Value.LogClaims)
{
Expand Down Expand Up @@ -168,7 +168,7 @@ protected virtual async Task<SignInResult> ExternalLoginSignInAsync(ExternalLogi
bypassTwoFactor: bypassTwofactor
);

Logger.LogInformation("External login use provider key '{ProviderKey}', name '{LoginProvider}', signin result: {SignInResult}", loginInfo.ProviderKey, loginInfo.LoginProvider, signInResult);
Logger.LogDebug("External login use provider key '{ProviderKey}', name '{LoginProvider}', signin result: {SignInResult}", loginInfo.ProviderKey, loginInfo.LoginProvider, signInResult);

return signInResult;
}
Expand All @@ -194,8 +194,6 @@ protected virtual async Task<SignInResult> ExternalLoginSignInAsync(ExternalLogi
loginDisplayName: loginInfo.ProviderDisplayName,
generateUserName: true);

Logger.LogInformation("User with name '{UserName}' created by external login with '{LoginProvider}' provider.", user.UserName, loginInfo.LoginProvider);

await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
Expand Down

0 comments on commit 2a0ea49

Please sign in to comment.