title: Using Log4net in ASP.NET MVC 3 but any log not store in sql server database?
body: <p>I have perform all the possible step as configuration in web.config, manage global.aspx page and so on but record not stored in database table.
  I have a contoller named Account controller when we enter username="sameer" and password is="singh123" but i entered  wrong password i want to save this error log in database
  
      
    
    
      
        </p>
  
  <pre><code>  &lt;logger name="SMSBA"&gt;
      &lt;appender-ref ref="ADONetAppender" /&gt;
    &lt;/logger&gt;
    &lt;param name="File" value="log-file.txt" /&gt;
    &lt;param name="AppendToFile" value="true" /&gt;
    &lt;rollingStyle value="Size" /&gt;
    &lt;maxSizeRollBackups value="10" /&gt;
    &lt;maximumFileSize value="10MB" /&gt;
    &lt;staticLogFileName value="true" /&gt;
    &lt;connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt;
    &lt;add name="SMSBA" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=SMSBA;" providerName="System.Data.SqlClient" /&gt;
    &lt;commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" /&gt;
    &lt;parameter&gt;
      &lt;parameterName value="@log_date" /&gt;
      &lt;dbType value="DateTime" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" /&gt;
    &lt;/parameter&gt;
    &lt;parameter&gt;
      &lt;parameterName value="@thread" /&gt;
      &lt;dbType value="String" /&gt;
      &lt;size value="255" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout" value="%thread" /&gt;
    &lt;/parameter&gt;
    &lt;parameter&gt;
      &lt;parameterName value="@log_level" /&gt;
      &lt;dbType value="String" /&gt;
      &lt;size value="50" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout" value="%level" /&gt;
    &lt;/parameter&gt;
    &lt;parameter&gt;
      &lt;parameterName value="@logger" /&gt;
      &lt;dbType value="String" /&gt;
      &lt;size value="255" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout" value="%logger" /&gt;
    &lt;/parameter&gt;
    &lt;parameter&gt;
      &lt;parameterName value="@message" /&gt;
      &lt;dbType value="String" /&gt;
      &lt;size value="4000" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout" value="%message" /&gt;
    &lt;/parameter&gt;
  &lt;/appender&gt;
  &lt;root&gt;
    &lt;level value="All"/&gt;
    &lt;appender-ref ref="AdoNetAppender_SqlServer"/&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>
  this is web.config file</p>
  
  <pre><code>public class MvcApplication : NinjectHttpApplication
  {
      private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
      public static void RegisterGlobalFilters(GlobalFilterCollection filters)
      {
          //filters.Add(new log4netExceptionFilter()); 
          filters.Add(new HandleErrorAttribute());
  
      }
  
      public static void RegisterRoutes(RouteCollection routes)
      {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
          routes.MapRoute(
              "Default", // Route name
              "{controller}/{action}/{id}", // URL with parameters
              new { controller = "Account", action = "LogOn", id = UrlParameter.Optional } // Parameter defaults
          );
  
  
  
  
  
      }
      protected override void OnApplicationStarted()
      {
          log4net.Config.XmlConfigurator.Configure();
          log4net.ILog log = log4net.LogManager.GetLogger(this.GetType());
          log.Info("stuff");
          log.Info("stuff");
  
          log.Debug("log Debug");
              log.Info("log Info");
              log.Warn("log Warn");
              log.Error("log Error");
              log.Fatal("log Fatal"); 
          SMSBAContextInitializer.Init();
          const string userName = "Administrator";
          if (Membership.GetUser(userName) == null)
          {
              Membership.CreateUser(userName, "test##123");
          }
          AreaRegistration.RegisterAllAreas();
          RegisterGlobalFilters(GlobalFilters.Filters);
          RegisterRoutes(RouteTable.Routes);
          RegisterAllControllersIn(Assembly.GetExecutingAssembly());
      }
  
      protected override IKernel CreateKernel()
      {
          var modules = new INinjectModule[]
          {
              new ServiceModule()
          };
  
          return new StandardKernel(modules);
      }
      internal class ServiceModule : NinjectModule
      {
          public override void Load()
          {
              Bind&lt;IFormsAuthenticationService&gt;().To&lt;FormsAuthenticationService&gt;();
              Bind&lt;IMembershipService&gt;().To&lt;AccountMembershipService&gt;();
              Bind&lt;MembershipProvider&gt;().ToConstant(Membership.Provider);
              Bind&lt;IDepartmentRepository&gt;().To&lt;DepartmentRepository&gt;();
              Bind&lt;IPersonnelRepository&gt;().To&lt;PersonnelRepository&gt;();
              Bind&lt;IPersonnelTitleRepository&gt;().To&lt;PersonnelTitleRepository&gt;();
              Bind&lt;IProcessInputRepository&gt;().To&lt;ProcessInputRepository&gt;();
              Bind&lt;ILoggingService&gt;().To&lt;Logging&gt;();
          }
      }
  }
  </code></pre>
  
  <p>this is global .asax
   file</p>
  
  <pre><code>public ActionResult LogOn(LogOnModel model, string returnUrl)
          {
              try
              {
                  if (ModelState.IsValid)
                  {
                      if (MembershipService.ValidateUser(model.UserName, model.Password))
                      {
                          FormsService.SignIn(model.UserName, model.RememberMe);
                          if (Url.IsLocalUrl(returnUrl))
                          {
                              return Redirect(returnUrl);
                          }
                          else
                          {
                              return RedirectToAction("Index", "Department");
                          }
                      }
                      else
                      {
                          _loggingService.Log("Password changed for user " + model.UserName);
                         // AddError("The user name or password provided is incorrect.");
                          ModelState.AddModelError("", "The user name or password provided is incorrect.");
                      }
                  }
  
              }
  
              catch (Exception ex)
              {
                  if (Logger.IsErrorEnabled)
                  {
                      AddError(ex.Message);
                      Logger.Error("login error : " + ex.Message);
                  }
              }
              return View(model);
          }
  </code></pre>
  
  <p>this is controller code</p>