Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions not being logged #93

Open
awjrowe opened this issue Oct 12, 2020 · 1 comment
Open

Exceptions not being logged #93

awjrowe opened this issue Oct 12, 2020 · 1 comment
Assignees

Comments

@awjrowe
Copy link

awjrowe commented Oct 12, 2020

I see there has been a previous bug registered about exceptions not getting passed to log4net so they can be output using the conversion pattern but it is marked as closed. I've run into the same problem and just tried your sample programs with the the controller modified as

    [HttpGet]
    public IEnumerable<WeatherForecast> Get()
    {
        var rng = new Random();
        WeatherForecast[] weatherForecast = Enumerable.Range(1, 5).Select(index => new WeatherForecast
        {
            Date = DateTime.Now.AddDays(index),
            TemperatureC = rng.Next(-20, 55),
            Summary = Summaries[rng.Next(Summaries.Length)]
        })
        .ToArray();

        _logger.LogTrace("Weather forecast ready!");
        _logger.LogError("Weather forecast broken!", new ApplicationException("Exception thrown"));

        return weatherForecast;
    }

and the Exception is not getting logged even though it is in your conversion patterns

		<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />

can you confirm this behaviour please.

@huorswords huorswords self-assigned this Nov 13, 2020
@FreyLuis
Copy link

II think the problem with the code above is the order of arguments provided to LogError. LogError(message, ex) tries to format the exception into the string, the correct one is LogError(ex, message).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants