c# webservice配置log4net打印日志

参考:https://cylycgs.blog.csdn.net/article/details/106243237

需要在webservice项目中添加Global.asax文件,修改Application_Start方法配置log4net,内容如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace IStatiionInterface
{
    public class Global : System.Web.HttpApplication
    {
        readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        protected void Application_Start(object sender, EventArgs e)
        {
            
            System.IO.FileInfo fileinfo = new System.IO.FileInfo(Server.MapPath("~/log4net.Config"));
            log4net.Config.XmlConfigurator.Configure(fileinfo);
            log.Info("网站己启动......");
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}

你可能感兴趣的:(C#,WebService)