Christopher Long
Christopher Long
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by Christopher Long on 8/25/2024 in #djs-questions
Reaction collector for every message in every channel
Hi, I'd like users to be able to react to any message in a guild with a specific emojji and have my bot react on that interaction. Is this possible and does anyone have any example of this sort of implementation?
7 replies
CC#
Created by Christopher Long on 3/21/2023 in #help
❔ Serilog filtering
We’re getting a lot of service health check spam in our logs, and we’re only really interested in when things go wrong. So what I've tried so far is to creating this LoggerConfigurationExtensions class that has methods for the default config as well as the specific log filtering. This class lives in a nuget package that our services make use of.
public static class LoggerConfigurationExtensions
{
private static readonly string[] LogsToExclude =
{
"/health",
"TcpHealthProbeService",
"HealthCheckMessage"
};

public static LoggerConfiguration ApplyDefaultConfiguration(
this LoggerConfiguration configuration,
HostBuilderContext context,
IServiceProvider provider)
=> configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(provider)
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("System", LogEventLevel.Warning)
.WriteTo.Console(new JsonFormatter(renderMessage: true));

public static LoggerConfiguration IgnoreHealthChecksPath(this LoggerConfiguration configuration) =>
configuration.Filter.ByExcluding(log =>
log.Level is LogEventLevel.Information &&
(log.Properties.Any(prop => LogsToExclude.Contains(prop.Value.ToString())) ||
IsRequestLoggingMiddleware(log)));

private static bool IsRequestLoggingMiddleware(LogEvent log) =>
log.Properties.TryGetValue("SourceContext", out var sourceContextProp) &&
log.Properties.TryGetValue("RequestPath", out var requestPathProp) &&
sourceContextProp.ToString().Contains("RequestLoggingMiddleware") &&
requestPathProp.ToString() == "/";
}
public static class LoggerConfigurationExtensions
{
private static readonly string[] LogsToExclude =
{
"/health",
"TcpHealthProbeService",
"HealthCheckMessage"
};

public static LoggerConfiguration ApplyDefaultConfiguration(
this LoggerConfiguration configuration,
HostBuilderContext context,
IServiceProvider provider)
=> configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(provider)
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("System", LogEventLevel.Warning)
.WriteTo.Console(new JsonFormatter(renderMessage: true));

public static LoggerConfiguration IgnoreHealthChecksPath(this LoggerConfiguration configuration) =>
configuration.Filter.ByExcluding(log =>
log.Level is LogEventLevel.Information &&
(log.Properties.Any(prop => LogsToExclude.Contains(prop.Value.ToString())) ||
IsRequestLoggingMiddleware(log)));

private static bool IsRequestLoggingMiddleware(LogEvent log) =>
log.Properties.TryGetValue("SourceContext", out var sourceContextProp) &&
log.Properties.TryGetValue("RequestPath", out var requestPathProp) &&
sourceContextProp.ToString().Contains("RequestLoggingMiddleware") &&
requestPathProp.ToString() == "/";
}
4 replies