Repository navigation
Log4Net integration should filter SDK logs #2953
Copy link
Copy link
Closed as not planned
Labels
.NETPull requests that update .net codePull requests that update .net codeFeatureNew feature or requestNew feature or requestLogsState: UnreproducibleState: Won't Dolog4net
Description
Particular case:
- Have a custom logger and add it to the SDK.
- Have an exception.
- Have the Sentry server respond with error
429 - Too Many Requests. - With
options.Debug = true;the SDK will log an error. - Due to the custom logger that error ends up in our Log4Net integration.
- Error gets captured as an event and sent to Sentry.
- Goto 3.
Repro:
using System.Net;
using log4net;
using log4net.Config;
using Microsoft.AspNetCore;
using Sentry.Extensibility;
[assembly: XmlConfigurator(Watch = true)]
namespace Sentry.Samples.AspNetCore.Basic;
public class Program
{
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseSentry(o =>
{
o.Dsn = "http://key@localhost:4999/123";
o.Debug = true;
o.DiagnosticLogger = new Log4NetDiagnosticLogger(Log);
})
// The App:
.Configure(app =>
{
app.UseRouting();
// An example ASP.NET Core middleware that throws an
// exception when serving a request to path: /throw
app.UseEndpoints(endpoints =>
{
// Reported events will be grouped by route pattern
endpoints.MapGet("/throw/{message?}", context =>
throw new Exception("An exception thrown from the ASP.NET Core pipeline"));
});
})
.Build();
}
public class Log4NetDiagnosticLogger : IDiagnosticLogger
{
private readonly ILog _log;
public Log4NetDiagnosticLogger(ILog log)
{
_log = log;
}
public bool IsEnabled(SentryLevel level)
{
return true;
}
public void Log(SentryLevel logLevel, string message, Exception exception = null, params object[] args)
{
switch (logLevel)
{
case SentryLevel.Debug:
_log.Debug(message);
break;
case SentryLevel.Info:
_log.Info(message);
break;
case SentryLevel.Warning:
_log.Warn(message);
break;
case SentryLevel.Error:
_log.Error(message);
break;
case SentryLevel.Fatal:
_log.Fatal(message);
break;
}
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
.NETPull requests that update .net codePull requests that update .net codeFeatureNew feature or requestNew feature or requestLogsState: UnreproducibleState: Won't Dolog4net
Projects
- StatusShow more project fieldsDone
Activity
jamescrosswell commentedon May 20, 2026
Discussed with @Flash0ver and decided this isn't a scenario we want to support (essentially the SDK user is piping Sentry's outputs back in as inputs). If users do want to capture Sentry's diagnostic logs somewhere other than the console, they still can - they just shouldn't try to capture them in Sentry itself (write to a file or something instead).
See details for the PR we closed for more info: