Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alexandre Locas 52 posts 219 karma points
    Feb 24, 2022 @ 19:25
    Alexandre Locas
    1

    How to log in ExceptionHandler ?

    Hi, i'm trying to add a exception handler wich will log the exception (in umbraco logs). How could this be done ?

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseExceptionHandler(err => {
                app.Run(async context =>
                {
                    // How can I log the error ?
                });
            });
    

    I have tried, without success, adding ILogger to Configure method parameters.

    Thank you

  • Brendan Rice 538 posts 1102 karma points
    Feb 24, 2022 @ 21:54
    Brendan Rice
    101

    Hi Alexandre,

    here's the official docs:

    https://our.umbraco.com/Documentation/Fundamentals/Code/Debugging/Logging/

    I think what you need to do is add the ILogger as a parameter in the constructor assign that to a private class variable which you can then access in the Configure method.

  • Alexandre Locas 52 posts 219 karma points
    Feb 25, 2022 @ 16:21
    Alexandre Locas
    2

    You are right, the following constructor in Startup.cs works :

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger)
    

    Thank you

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies