I'm trying to send log messages to my gmail account but it keeps not working. I've tried changing ports and changing threshold value but it's not working. When I try writing logs in file everything is ok, so I think the problem is in log4net.config file.
My log4net configuration file contains:
<log4net>
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="[email protected]" />
<from value="[email protected]" />
<subject value="Crash log" />
<smtpHost value="smtp.gmail.com" />
<authentication value="Basic" />
<port value="465" />
<username value="myusername" />
<password value="mypass" />
<bufferSize value="1" />
<EnableSsl value="true"/>
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="DEBUG"/>
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d{hh:mm:ss} %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="SmtpAppender"/>
</root>
</log4net>
In my Startup.cs file I have:
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
And my example code is:
public class HomeController : Controller
{
private static readonly ILog log = LogManager.GetLogger(typeof(HomeController));
public HomeController()
{
}
public IActionResult Index()
{
return View();
}
public IActionResult About()
{
ViewData["Message"] = "Your application description page.";
ViewData["Title"] = "title";
log.Warn("test test", new NullReferenceException("missing"));
log.Debug("test test", new NullReferenceException("missing"));
log.Error("test test", new NullReferenceException("missing"));
log.Fatal("test test", new NullReferenceException("missing"));
return View();
}
}
Am I making something wrong. I tried everything
log4net's SmtpAppender is not supported in .net core yet.
Supported frameworks: https://logging.apache.org/log4net/release/framework-support.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With