΢ Ͷ ^ ھ

苏州队cba赛程 :ASP.NET MVCʹlog4netČFʾ

cba㶫 www.axwwg.com  •rg2020-01-25 00:02:20   ߣ   ҪuՓ(0)

ԼҪŪһ־ӛ䛹ǰҲŪ^ ǶŪһ ˎʮڴӛһ
һlog4net.dll
ڶ ʾ£ ֱ

ԼҪŪһ־ӛ䛹ǰҲŪ^ ǶŪһ ˎʮڴӛһ

һlog4net.dll

ڶ  ʾ£ ֱWeb.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <configSections>
  <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
 </configSections>
 <log4net>
  <logger name="Student">
   <level value="ALL" />
   <appender-ref ref="rollingFile" />
  </logger>
  <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">
   <File value="log/" />
   <DatePattern value="yyyy-MM-dd".txt"" />
   <StaticLogFileName value="false" />
   <maxSizeRollBackups value="-1" />
   <RollingStyle value="Date" />
   <AppendToFile value="false" />
   <MaximumFileSize value="1024MB" />
   <layout type="log4net.Layout.PatternLayout,log4net">
    <ConversionPattern value="%-38m %-7p %-20d %n" />
   </layout>
  </appender>
 </log4net>
 
<!--IJ??-->
 <appSettings>
  <add key="webpages:Version" value="3.0.0.0" />
  <add key="webpages:Enabled" value="false" />
  <add key="ClientValidationEnabled" value="true" />
  <add key="UnobtrusiveJavaScriptEnabled" value="true" />
 </appSettings>
 <system.web>
  <compilation debug="true" targetFramework="4.7.2" />
  <httpRuntime targetFramework="4.7.2" />
 </system.web>
 
 
</configuration>

Global.asax.csļ     log4net.Config.XmlConfigurator.Configure(); £

  public class MvcApplication : System.Web.HttpApplication
  {
    protected void Application_Start()
    {
      AreaRegistration.RegisterAllAreas();
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
      RouteConfig.RegisterRoutes(RouteTable.Routes);
      BundleConfig.RegisterBundles(BundleTable.Bundles);
      log4net.Config.XmlConfigurator.Configure();
    }
  }

IJLog Ȼʹü  @Ҫע֌ ҵaеע

  public class LogHelper
  {
    //Studentļ <logger name="Student"> nameֵ
    private static log4net.ILog log = log4net.LogManager.GetLogger("Student");
 
    public static void Debug(object message, Exception e)
    {
      log.Debug(message, e);
    }
 
    public static void Debug(object message)
    {
      log.Debug(message);
    }
 
    public static void Info(object message)
    {
      log.Info(message);
    }
 
    public static void Warn(object message)
    {
      log.Warn(message);
    }
 
    public static void Error(object message)
    {
      log.Error(message);
    }
 
    public static void Error(object message, Exception e)
    {
      log.Error(message, e);
    }
 
    public static void Log(object message)
    {
      log.Info(message);
    }
  }

ļăݱ^ ԔԼٶȿ^Ԕļ

ϾDZĵȫϣҵČWҲϣҶ֧_֮

ܸdȤ:

  • asp.net log4netʹ÷

P