How to use Log4net from Nuget with Visual Studio in the ASP.NET Web Form (Easy method)

后端 未结 1 823
你的背包
你的背包 2020-12-22 08:15

Hi all I know how to quick and easy way to build the Log4Net in my ASP.NET MVC project [Reference],however how to do it in pure \" Web Form \" project, please help me to sol

1条回答
  •  悲哀的现实
    2020-12-22 09:00

    4 steps to handle this issue for web form
    Step 1:
    Using Nuget to get the Log4Net

    Step 2:
    In Global please put this sentence "log4net.Config.XmlConfigurator.Configure();" in the Application_Start

    Step 3: In the Web.Config please write down as following code in the web.config

     
        

    Final step:
    Putting as following code in one page where you want to record the log

      private static log4net.ILog Log { get; set; }= log4net.LogManager.GetLogger(typeof(_03_account));
    
            protected void Page_Load(object sender, EventArgs e)
            {
    
                Log.Debug("Debug message");
                //log.Warn("Warn message");
                //log.Error("Error message");
                //log.Fatal("Fatal message");
            }
    

    0 讨论(0)
提交回复
热议问题