Skip to content

Commit bb72a82

Browse files
committed
Don't log errors that occur when logging errors
1 parent 00e2cfa commit bb72a82

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Helpers/LogChannelHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static async Task<DiscordMessage> LogMessageAsync(string key, DiscordMess
126126
}
127127
catch (Exception ex)
128128
{
129-
Program.discord.Logger.LogError(ex, "Error ocurred trying to send message to key {key}", key);
129+
Program.discord.Logger.LogError(Program.LogChannelErrorID, ex, "Error ocurred trying to send message to key {key}", key);
130130
return null;
131131
}
132132
}

Program.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class Program : BaseCommandModule
4545
public static ConnectionMultiplexer redis;
4646
public static IDatabase db;
4747
internal static EventId CliptokEventID { get; } = new EventId(1000, "Cliptok");
48+
internal static EventId LogChannelErrorID { get; } = new EventId(1001, "LogChannelError");
49+
4850

4951
public static string[] avatars;
5052

@@ -78,9 +80,11 @@ static async Task Main(string[] _)
7880
var logFormat = "[{Timestamp:yyyy-MM-dd HH:mm:ss zzz}] [{Level}] {Message}{NewLine}{Exception}";
7981

8082
var loggerConfig = new LoggerConfiguration()
81-
.WriteTo.Console(outputTemplate: logFormat, theme: AnsiConsoleTheme.Literate)
83+
.WriteTo.Logger(lc =>
84+
lc.Filter.ByExcluding("EventId.Id = 1001")
8285
.WriteTo.DiscordSink(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, outputTemplate: logFormat)
83-
.Filter.ByExcluding(log => { return log.ToString().Contains("DSharpPlus.Exceptions.NotFoundException: Not found: NotFound"); });
86+
)
87+
.WriteTo.Console(outputTemplate: logFormat, theme: AnsiConsoleTheme.Literate);
8488

8589
string token;
8690
var json = "";

0 commit comments

Comments
 (0)