catch (Excetion ex)
{
_logger.Logerror(ex," " )
}
return xyx;
catch (Excetion ex)
{
_logger.Logerror(ex," " )
}
return xyx;
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Aug 18, 2023, 4:51 AM EDT
Make sure that you have declared and instantiated the _logger object properly before using it. You might need to create an instance of a logging library, like ILogger, and assign it to the _logger variable.
using Microsoft.Extensions.Logging; public class YourClass { private readonly ILogger _logger; public YourClass(ILogger logger) { _logger = logger; } public ReturnType YourMethod() { try { // Your code that might throw an exception } catch (Exception ex) { _logger.LogError(ex, "An error occurred"); } return xyz; } }Chinna Kanchireddy93 reputationPosted Aug 18, 2023, 7:52 AM EDT
Yes It's correct Thank you so much