Merge pull request #1951 from DuendeSoftware/beh/sourcegenerators-for-v2license-logs

This commit is contained in:
Joe DeCock 2025-04-07 18:56:14 -05:00 committed by GitHub
commit bcb46fa645
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 3 deletions

View file

@ -90,7 +90,7 @@ internal class LicenseAccessor(IdentityServerOptions options, ILogger<LicenseAcc
var validateResult = handler.ValidateTokenAsync(licenseKey, parms).Result;
if (!validateResult.IsValid)
{
logger.LogCritical(validateResult.Exception, "Error validating the Duende software license key");
logger.ErrorValidatingLicenseKey(validateResult.Exception);
}
return validateResult.ClaimsIdentity?.Claims.ToArray() ?? [];

View file

@ -21,7 +21,7 @@ internal class LicenseExpirationChecker(
if (!_expiredLicenseWarned && !license.Current.Redistribution && IsExpired)
{
_expiredLicenseWarned = true;
_logger.LogError("The IdentityServer license is expired. In a future version of IdentityServer, license expiration will be enforced after a grace period.");
_logger.LicenseHasExpired();
}
}

View file

@ -0,0 +1,29 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.
using Microsoft.Extensions.Logging;
namespace Duende.IdentityServer.Licensing.V2;
internal static class LicenseLogParameters
{
public const string Threshold = "Threshold";
}
internal static partial class Log
{
[LoggerMessage(
LogLevel.Critical,
message: "Error validating the Duende software license key")]
public static partial void ErrorValidatingLicenseKey(this ILogger logger, Exception ex);
[LoggerMessage(
LogLevel.Error,
message: "The IdentityServer license is expired. In a future version of IdentityServer, license expiration will be enforced after a grace period.")]
public static partial void LicenseHasExpired(this ILogger logger);
[LoggerMessage(LogLevel.Error,
Message =
$"You are using IdentityServer in trial mode and have exceeded the trial threshold of {{{LicenseLogParameters.Threshold}}} requests handled by IdentityServer. In a future version, you will need to restart the server or configure a license key to continue testing. For more information, please see https://docs.duendesoftware.com/trial-mode.")]
public static partial void TrialModeRequestCountExceeded(this ILogger logger, ulong threshold);
}

View file

@ -28,12 +28,14 @@ internal class ProtocolRequestCounter(
{
return;
}
var total = Interlocked.Increment(ref _requestCount);
if (total <= Threshold || _warned)
{
return;
}
_logger.LogError($"You are using IdentityServer in trial mode and have exceeded the trial threshold of {Threshold} requests handled by IdentityServer. In a future version, you will need to restart the server or configure a license key to continue testing. For more information, please see https://docs.duendesoftware.com/trial-mode.");
_logger.TrialModeRequestCountExceeded(Threshold);
_warned = true;
}
}