1

I added email logging to my .net core application, like here:

https://github.com/shawnwildermuth/WilderBlog/tree/master/src/WilderBlog/Logger

using the following in Startup.cs

loggerfactory.AddEmail(mailService, Microsoft.Extensions.Logging.LogLevel.Critical);

LogLevel.Critical:

Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention

So I set out to test this in a controller action:

public ContentResult ProduceError()
{
    var foo = new StackOverflower();
    System.Console.WriteLine(foo.MyText);
    return Content("<html><body></body></html>", "text/html");
}

public class StackOverflower
{
    private string m_MyText;

    public string MyText
    {
        get { return MyText; }
        set { this.m_MyText = value; }
    }
}

But this logs NOTHING.

Now, since the logging works fine for non-critical errors, I have one question:
If it can't log critical errors, why have a LogLevel for it ?
Or am I missing something ?

  • [MSDN](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging?tabs=aspnetcore2x) ```For failures that require immediate attention. Examples: data loss scenarios, out of disk space.``` - where is dataloss/disk space in your sample? – tym32167 Sep 20 '17 at 08:19
  • 3
    `someLogger.LogCritical("This is Critical");` successfully works (prints message in console when console logger enabled). Are you sure the problem is not in your logger class itself? – Dmitry Sep 20 '17 at 08:33
  • @Dmitry: Logs on a stackoverflow ? My logger works in non-critical cases, so I don't think that is the problem. Maybe the problem is that it can't do more than console.WriteLine when critical. –  Sep 20 '17 at 08:52
  • @User1: No, I simple wrote `LogCritical() in the middle of my currently opened netcoreapp2.0 app and I see that it works Ok, so "it can't log critical errors" is not true. If you suspect that you problem is related to stack overflow or other your-app-specific reasons - you should edit your question to be more specific. Also [MCVE](https://stackoverflow.com/help/mcve) may be useful too. – Dmitry Sep 20 '17 at 14:07
  • @Dmitry: I thought that is sufficiently clear - well apparently not. It's just that a stackoverflow-error perfectly fits the description "Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention". But apparently, this is not so. –  Sep 20 '17 at 15:06
  • So you claim that with `StackOverflowException` call to `LogCritical` produces nothing, while with any other exception works perfectly? Can you make MCVE for this? – Dmitry Sep 20 '17 at 16:18
  • 2
    Are you filling the stack in code not shown ? You cant do anything on this thread if your stack has overflowed you certainly cant call a method . Stack overflow / out of memory = dead..to late to log it may work via a static call which releases another prepared thread ( maybe a waithandle) but I doubt it. .. – user1496062 Oct 10 '17 at 08:01

0 Answers0