Try placing your code from Application_Start
into Session_Start
. Application_Start
is only run the first time your site is called after the corresponding ApplicationPool
started. Session_Start
is called for every user.
Logging functionality not working ASP.NET C#
Question
My log4net stopped working and just won't start again!
My web.config file:
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="FileAppender"
type="log4net.Appender.RollingFileAppender" >
<encoding value="utf-8" />
<lockingModel value="MinimalLock" />
<file value="App_Data\Logs\Test-log.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] – %message%newline" />
</layout>
</appender>
<root>
<level value="All" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
The class that uses it:
using log4net;
public class Connection
{
private static readonly ILog log = LogManager.GetLogger(typeof(Connection));
My Global.asax
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"));
}
Why is the below executing but not logging/creating a logfile even? The output window isn't throwing any errors.
log.Debug("Entering Function: Insert_PatientTable");
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow