try{ // code that may throw an exception } catch(Exception ex){ logger.LogError(ex, "An error occurred"); // other exception handling code }In the above example, when an exception is caught, the logger will log the exception with the error level and the message "An error occurred". This helps in identifying and fixing the issue later on. The ILogger interface is a part of the Microsoft.Extensions.Logging namespace, which is generally used in .NET Core applications.