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

Level "Critical" not supported #29

Closed
E4est opened this issue May 12, 2022 · 6 comments · Fixed by #31 or #38
Closed

Level "Critical" not supported #29

E4est opened this issue May 12, 2022 · 6 comments · Fixed by #31 or #38

Comments

@E4est
Copy link

E4est commented May 12, 2022

I can't filter my logs by Level "Critical".
When I add a critical entry, no level is displayed for the entry.

image

@mo-esmp
Copy link
Member

mo-esmp commented May 13, 2022

Thanks for reporting this.

@followynne we forgot log lever Critical. Do you have time to fix this?

@followynne
Copy link
Member

@mo-esmp yes, I'll try to give it a look asap this weekend 👍

@E4est
Copy link
Author

E4est commented Jun 7, 2022

Hello,

I came back from my vacation and just had the chance to test it.
Now I'm realizing that my initial issue was described poorly.

On 2.1.2 it still looks like this:
image

but apparently there is a white text in a white box saying "Fatal".
image

It seems like Serilog saves critical logs as "Fatal".

(I'm using the MsSqlServerProvider, if that's relevant.)

@followynne
Copy link
Member

Hey @E4est
Thanks for reporting back.
Can you please attach the sample log you're using in the screenshot? (json, text, as you prefer...)

I'll use it to test more in depth the feat. 😊

@E4est
Copy link
Author

E4est commented Jun 7, 2022

Sure :)

// The JSON payload for the screenshot.
{
    "level": "critical",
    "messageTemplate": "I hope critical works now. {Remark}",
    "properties": [
        "That would be so cool."
    ]
}
// The model posted to the log API.
public class LogModel
{
    public string? MessageTemplate { get; set; }

    public string? Level { get; set; }

    public ICollection<object> Properties { get; set; } = new List<object>();
}

// The API controller receiving logs.
[Route("")]
[ApiController]
public class LoggerController : ControllerBase
{
    private readonly ILogger _logger;

    public LoggerController(ILogger<LoggerController> logger)
    {
        _logger = logger;
    }

    [HttpPost("")]
    public IActionResult Insert(LogModel model)
    {
        switch (model.Level?.ToUpperInvariant())
        {
            case "CRITICAL":
                _logger.LogCritical(model.MessageTemplate, model.Properties.ToArray());
                break;
            case "DEBUG":
                _logger.LogDebug(model.MessageTemplate, model.Properties.ToArray());
                break;
            case "ERROR":
                _logger.LogError(model.MessageTemplate, model.Properties.ToArray());
                break;
            case "TRACE":
                _logger.LogTrace(model.MessageTemplate, model.Properties.ToArray());
                break;
            case "WARNING":
                _logger.LogWarning(model.MessageTemplate, model.Properties.ToArray());
                break;
            default:
                LogInvalidModel(model);
                return UnprocessableEntity("invalid level");
        }

        return NoContent();
    }

    private void LogInvalidModel(LogModel model)
    {
        _logger.LogError(
            "Invalid log model. Received: '{Request}'.",
            JsonConvert.SerializeObject(model));
    }
}

@followynne
Copy link
Member

@E4est
Thanks a lot, I'm not sure when I'll be able to take a look at it but I'll try to do it asap, I'll keep you posted 😊

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