Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Log an Error Without Throwing an Exception #8329


User avatar
0
wizgod created

Greetings Programs!

I've got a method with a try/catch in which I throw a UserFriendlyException.

I'm going to be calling it from a hangfire job now within a foreach loop and I was wondering if there is a way to log the exception without throwing it so it doesn't stop the job?

Thanks,

Wg


5 Answer(s)
  • User Avatar
    0
    BobIngham created

    @wizgod, UserFriendlyException is designed to return an error message to the client. If you're throwing it in a Hangfire job there is no client, use standard exception handling or simply log the error.

  • User Avatar
    0
    maliming created
    Support Team

    simply log the error.

    Just log it without throwing an exception.

    try
    {
    	//you code
    }
    catch (Exception exception)
    {
    	_logger.Fatal(ex.ToString()); // Just log it without throwing an exception.
    }
    
  • User Avatar
    0
    wizgod created

    Hi @maliming,

    I am using Castle.Core.Logging and injecting ILogger for the _ logger instance, is this correct?

    Thanks,

    Wg

  • User Avatar
    0
    maliming created
    Support Team

    hi @wizgod

    see https://aspnetboilerplate.com/Pages/Documents/Logging

  • User Avatar
    0
    ismcagdas created
    Support Team

    This issue is closed because of no recent activity. Please create a new issue if you are still having this problem.