Closed Alvin-Prasla closed 2 years ago
Figured out. Below worked for me. I added a method in Log4netExtensions.cs class
namespace Utility.Log
{
public static class Log4netExtensions
{
private static readonly string LOG_CONFIG_FILE = @"./Utility/Log/log4net.config";
private static readonly string SMTP_APPENDER = @"/log4net/appender[@type='log4net.Helper.Core.SMTPAppender']";
public static ILoggerFactory AddLog4Net(this ILoggerFactory factory)
{
factory.AddProvider(new Log4NetProvider(LOG_CONFIG_FILE, SMTP_APPENDER));
return factory;
}
public static ILoggingBuilder AddLog4Net(this ILoggingBuilder builder)
{
builder.Services.AddSingleton<ILoggerProvider>(new Log4NetProvider(LOG_CONFIG_FILE, SMTP_APPENDER));
return builder;
}
}
}
Anyone knows how to use SMTPAppender for sending email when Error occurs. I had used below custom code but in .NET 6.0 I am unable to call custom AddLog4Net method. Ref: https://laptrinhx.com/c-net-core-3-0-and-log4net-with-email-alerts-3481421569/
Log4netExtensions.cs
Program.cs
Thanks