generated from ricardo/MVCLogin
29 lines
1.1 KiB
C#
29 lines
1.1 KiB
C#
using Microsoft.Extensions.Logging;
|
|
|
|
namespace SumaTube.Crosscutting.Logging.Extensions
|
|
{
|
|
public static class LoggerExtensions
|
|
{
|
|
public static void LogMethodEntry<T>(this ILogger<T> logger, string methodName, params object[] parameters)
|
|
{
|
|
logger.LogInformation("Entering method {MethodName} with parameters {@Parameters}", methodName, parameters);
|
|
}
|
|
|
|
public static void LogMethodExit<T>(this ILogger<T> logger, string methodName, object result = null)
|
|
{
|
|
logger.LogInformation("Exiting method {MethodName} with result {@Result}", methodName, result);
|
|
}
|
|
|
|
public static void LogException<T>(this ILogger<T> logger, Exception exception, string message = null)
|
|
{
|
|
logger.LogError(exception, message ?? "An error occurred: {ErrorMessage}", exception.Message);
|
|
}
|
|
|
|
public static void LogPerformance<T>(this ILogger<T> logger, string operation, long elapsedMilliseconds)
|
|
{
|
|
logger.LogInformation("Performance: {Operation} took {ElapsedMilliseconds} ms", operation, elapsedMilliseconds);
|
|
}
|
|
}
|
|
}
|
|
|