Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>

<!-- NuGet -->
<Version>4.6.3</Version>
<Version>4.6.4</Version>
<AssemblyVersion>4.6.0</AssemblyVersion>
<FileVersion>4.6.0</FileVersion>
<Authors>Jon Sagara</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public void OnException(ExceptionContext context)
log.AppendLine(CultureInfo.InvariantCulture, $" Raw URL: {context.HttpContext.Request.GetEncodedUrl()}");
}

_logger.UnhandledException(context.Exception, log.ToString());
if (_logger.IsEnabled(LogLevel.Error))
{
_logger.Error_UnhandledException(context.Exception, log.ToString());
}

// Don't set it to handled. Let it continue through the pipeline.
}
Expand All @@ -82,5 +85,5 @@ public void OnException(ExceptionContext context)
internal static partial class UnhandledExceptionFilterLogger
{
[LoggerMessage(EventId = 0, Level = LogLevel.Error, Message = "{message}")]
public static partial void UnhandledException(this ILogger logger, Exception ex, string message);
public static partial void Error_UnhandledException(this ILogger logger, Exception ex, string message);
}
2 changes: 1 addition & 1 deletion src/Sagara.Core.Caching/RedisAdminCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ await server
catch (Exception ex)
{
// Don't let the cache server bring down the application.
_logger.UnhandledException(ex, command: "FLUSHALL", key: "(all keys)");
_logger.Error_UnhandledException(ex, command: "FLUSHALL", key: "(all keys)");
}
}

Expand Down
37 changes: 20 additions & 17 deletions src/Sagara.Core.Caching/RedisCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ protected ConnectionMultiplexer InitializeConnectionMultiplexer(ConfigurationOpt
// Log connection and error events.
multiplexer.ConnectionFailed += (sender, e) =>
{
_logger.OnConnectionFailed(e.Exception, logPrefix, e.ConnectionType, e.EndPoint, e.FailureType);
_logger.Error_OnConnectionFailed(e.Exception, logPrefix, e.ConnectionType, e.EndPoint, e.FailureType);
};

multiplexer.ConnectionRestored += (sender, e) =>
{
_logger.OnConnectionRestored(e.Exception, logPrefix, e.ConnectionType, e.EndPoint, e.FailureType);
_logger.Information_OnConnectionRestored(e.Exception, logPrefix, e.ConnectionType, e.EndPoint, e.FailureType);
};

multiplexer.ErrorMessage += (sender, e) =>
{
_logger.OnErrorMessage(logPrefix, e.EndPoint, e.Message);
_logger.Error_OnErrorMessage(logPrefix, e.EndPoint, e.Message);
};

multiplexer.ServerMaintenanceEvent += (sender, e) =>
{
_logger.OnServerMaintenanceEvent(logPrefix, e.ReceivedTimeUtc, e.StartTimeUtc, e.RawMessage);
_logger.Warning_OnServerMaintenanceEvent(logPrefix, e.ReceivedTimeUtc, e.StartTimeUtc, e.RawMessage);
};

return multiplexer;
Expand Down Expand Up @@ -107,7 +107,7 @@ protected ConnectionMultiplexer InitializeConnectionMultiplexer(ConfigurationOpt
catch (Exception ex)
{
// Don't let cache server unavailability bring down the application.
_logger.UnhandledException(ex, command: "GET", key: key);
_logger.Error_UnhandledException(ex, command: "GET", key: key);
}

return default;
Expand Down Expand Up @@ -143,7 +143,7 @@ protected ConnectionMultiplexer InitializeConnectionMultiplexer(ConfigurationOpt
var db = GetDatabase();

var redisResult = await db
.ScriptEvaluateAsync(SLIDING_EXPIRATION_LUA_SCRIPT, new RedisKey[] { key }, new RedisValue[] { expiry.TotalSeconds })
.ScriptEvaluateAsync(script: SLIDING_EXPIRATION_LUA_SCRIPT, keys: [key], values: [expiry.TotalSeconds])
.ConfigureAwait(false);

var value = (string?)redisResult;
Expand All @@ -155,7 +155,7 @@ protected ConnectionMultiplexer InitializeConnectionMultiplexer(ConfigurationOpt
catch (Exception ex)
{
// Don't let cache server unavailability bring down the application.
_logger.UnhandledException(ex, command: "GET/EXPIRE", key: key);
_logger.Error_UnhandledException(ex, command: "GET/EXPIRE", key: key);
}

return default;
Expand All @@ -178,7 +178,7 @@ protected ConnectionMultiplexer InitializeConnectionMultiplexer(ConfigurationOpt
var db = GetDatabase();

var redisResult = db
.ScriptEvaluate(SLIDING_EXPIRATION_LUA_SCRIPT, new RedisKey[] { key }, new RedisValue[] { expiry.TotalSeconds });
.ScriptEvaluate(script: SLIDING_EXPIRATION_LUA_SCRIPT, keys: [key], values: [expiry.TotalSeconds]);

var value = (string?)redisResult;
if (!string.IsNullOrWhiteSpace(value))
Expand All @@ -189,7 +189,7 @@ protected ConnectionMultiplexer InitializeConnectionMultiplexer(ConfigurationOpt
catch (Exception ex)
{
// Don't let cache server unavailability bring down the application.
_logger.UnhandledException(ex, command: "GET/EXPIRE", key: key);
_logger.Error_UnhandledException(ex, command: "GET/EXPIRE", key: key);
}

return default;
Expand Down Expand Up @@ -219,7 +219,7 @@ public async Task<bool> SetAsync(string key, object value, TimeSpan? expiry = nu
catch (Exception ex)
{
// Don't let cache server unavailability bring down the application.
_logger.UnhandledException(ex, command: "SET", key: key);
_logger.Error_UnhandledException(ex, command: "SET", key: key);
}

return false;
Expand Down Expand Up @@ -247,7 +247,7 @@ public bool Set(string key, object value, TimeSpan? expiry = null)
catch (Exception ex)
{
// Don't let cache server unavailability bring down the application.
_logger.UnhandledException(ex, command: "SET", key: key);
_logger.Error_UnhandledException(ex, command: "SET", key: key);
}

return false;
Expand Down Expand Up @@ -300,7 +300,7 @@ public async Task<bool> RemoveAsync(string key)
catch (Exception ex)
{
// Don't let cache server unavailability bring down the application.
_logger.UnhandledException(ex, command: "DEL", key: key);
_logger.Error_UnhandledException(ex, command: "DEL", key: key);
}

return false;
Expand Down Expand Up @@ -331,7 +331,10 @@ public async Task<long> RemoveAsync(IReadOnlyCollection<string> keys)
catch (Exception ex)
{
// Don't let cache server unavailability bring down the application.
_logger.UnhandledException(ex, command: "DEL", key: string.Join(" ", keys));
if (_logger.IsEnabled(LogLevel.Error))
{
_logger.Error_UnhandledException(ex, command: "DEL", key: string.Join(" ", keys));
}
}
}

Expand Down Expand Up @@ -374,13 +377,13 @@ public async Task<long> IncrementAndExpireOnCreateAsync(string key, TimeSpan exp
// INCR and return the counter value. Will return 1 if it didn't already exist. Expire is only
// called if the key didn't already exist.
return (long)await db
.ScriptEvaluateAsync(INCREMENT_AND_EXPIRE_ON_CREATE_LUA_SCRIPT, new RedisKey[] { key }, new RedisValue[] { expiry.TotalSeconds })
.ScriptEvaluateAsync(script: INCREMENT_AND_EXPIRE_ON_CREATE_LUA_SCRIPT, keys: [key], values: [expiry.TotalSeconds])
.ConfigureAwait(false);
}
catch (Exception ex)
{
// Don't let cache server unavailability bring down the application.
_logger.UnhandledException(ex, command: "INCR and EXPIRE On Create", key: key);
_logger.Error_UnhandledException(ex, command: "INCR and EXPIRE On Create", key: key);
}

return 0L;
Expand Down Expand Up @@ -414,7 +417,7 @@ await GetSubscriber()
catch (Exception ex)
{
// Don't let cache server unavailability bring down the application.
_logger.UnhandledSubscribeException(ex, channel);
_logger.Error_UnhandledSubscribeException(ex, channel);
}
}

Expand All @@ -432,7 +435,7 @@ public async Task<long> PublishAsync(RedisChannel channel, RedisValue message)
catch (Exception ex)
{
// Don't let cache server unavailability bring down the application.
_logger.UnhandledPublishException(ex, channel, message);
_logger.Error_UnhandledPublishException(ex, channel, message);
}

return 0L;
Expand Down
14 changes: 7 additions & 7 deletions src/Sagara.Core.Caching/RedisCacheLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ namespace Sagara.Core.Caching;
internal static partial class RedisCacheLogger
{
[LoggerMessage(Level = LogLevel.Error, Message = "{LogPrefix}ConnectionFailed: Connection type '{ConnectionType}' on EndPoint '{EndPoint}' reported ConnectionFailureType '{FailureType}'")]
public static partial void OnConnectionFailed(this ILogger logger, Exception? ex, string logPrefix, ConnectionType connectionType, EndPoint? endPoint, ConnectionFailureType failureType);
public static partial void Error_OnConnectionFailed(this ILogger logger, Exception? ex, string logPrefix, ConnectionType connectionType, EndPoint? endPoint, ConnectionFailureType failureType);

[LoggerMessage(Level = LogLevel.Information, Message = "{LogPrefix}ConnectionRestored: Connection type '{ConnectionType}' on EndPoint '{EndPoint}' reported ConnectionFailureType '{FailureType}'")]
public static partial void OnConnectionRestored(this ILogger logger, Exception? ex, string logPrefix, ConnectionType connectionType, EndPoint? endPoint, ConnectionFailureType failureType);
public static partial void Information_OnConnectionRestored(this ILogger logger, Exception? ex, string logPrefix, ConnectionType connectionType, EndPoint? endPoint, ConnectionFailureType failureType);

[LoggerMessage(Level = LogLevel.Error, Message = "{LogPrefix}ErrorMessage: Server '{EndPoint}' reported this error message: {Message}")]
public static partial void OnErrorMessage(this ILogger logger, string logPrefix, EndPoint? endPoint, string message);
public static partial void Error_OnErrorMessage(this ILogger logger, string logPrefix, EndPoint? endPoint, string message);

[LoggerMessage(Level = LogLevel.Warning, Message = "{LogPrefix}ServerMaintenanceEvent: Server maintenance event received at {ReceivedTimeUtc}. Expected start time is {StartTimeUtc}. Raw message: {RawMessage}")]
public static partial void OnServerMaintenanceEvent(this ILogger logger, string logPrefix, DateTime receivedTimeUtc, DateTime? startTimeUtc, string? rawMessage);
public static partial void Warning_OnServerMaintenanceEvent(this ILogger logger, string logPrefix, DateTime receivedTimeUtc, DateTime? startTimeUtc, string? rawMessage);

[LoggerMessage(Level = LogLevel.Error, Message = "Unhandled exception trying to async {Command} {Key}")]
public static partial void UnhandledException(this ILogger logger, Exception ex, string command, string key);
public static partial void Error_UnhandledException(this ILogger logger, Exception ex, string command, string key);

[LoggerMessage(Level = LogLevel.Error, Message = "Unhandled exception trying to SUBSCRIBE {Channel}")]
public static partial void UnhandledSubscribeException(this ILogger logger, Exception ex, RedisChannel channel);
public static partial void Error_UnhandledSubscribeException(this ILogger logger, Exception ex, RedisChannel channel);

[LoggerMessage(Level = LogLevel.Error, Message = "Unhandled exception trying to async PUBLISH {Channel} {Message}")]
public static partial void UnhandledPublishException(this ILogger logger, Exception ex, RedisChannel channel, RedisValue message);
public static partial void Error_UnhandledPublishException(this ILogger logger, Exception ex, RedisChannel channel, RedisValue message);
}
5 changes: 5 additions & 0 deletions src/Sagara.Core/Extensions/StringComparerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

public static class StringComparerExtensions
{
// As of .NET 10 RC 2, the compiler gives us the following warning:
// warning CA1034: Do not nest type . Alternatively, change its accessibility so that it is not externally visible.
//
// We are properly using the new extension members. I think we just need to wait for the analyzer to be
// updated so that this warning goes away.
#if NET10_0_OR_GREATER
extension(StringComparer)

Check warning on line 13 in src/Sagara.Core/Extensions/StringComparerExtensions.cs

View workflow job for this annotation

GitHub Actions / run_test

Do not nest type . Alternatively, change its accessibility so that it is not externally visible. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1034)

Check warning on line 13 in src/Sagara.Core/Extensions/StringComparerExtensions.cs

View workflow job for this annotation

GitHub Actions / pack_nuget

Do not nest type . Alternatively, change its accessibility so that it is not externally visible. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1034)
{
public static StringComparer Numeric
=> StringComparer.Create(CultureInfo.CurrentCulture, CompareOptions.NumericOrdering);
Expand Down
6 changes: 3 additions & 3 deletions src/Sagara.Core/Sagara.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.6" />
<PackageReference Include="System.Text.Json" Version="8.0.6" NoWarn="NU1510" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.10" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.10" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.10" />
<PackageReference Include="System.Text.Json" Version="9.0.10" />
<PackageReference Include="System.Text.Json" Version="9.0.10" NoWarn="NU1510" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="System.Text.Json" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="System.Text.Json" Version="10.0.0-rc.2.25502.107" NoWarn="NU1510" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading