How to use Log4net in your Web Services

by Emanuele 4/28/2008 3:29:00 PM

You can use Log4net to log your web services activities.
The implementation is the same of web application.
There are two ways to implement the initialization function in your web services.
The first solution is put your code into the Global.asax.
The second solution is put your code into the code behind file of Global.asax.

First of all add Global.asax file in your solution. Right click on the main project and select "Add New Item". In the new window, select "Global Application Class" and click Ok.

Open the Global.asax and put this code:

<%@ Application Language="C#" %>
<script runat="server">
     private void Application_Start(Object sender, EventArgs e)
     {
          log4net.Config.DOMConfigurator.Configure();
     }
</script>

If you want use the code behind file, open the Global.asax.cs file and put this code:

namespace MyWebServices
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(Object sender, EventArgs e)
        {
            log4net.Config.DOMConfigurator.Configure();
        }
    }
}

The Application_Start method is invoked when the Web Service is run for the first time (or reloaded).

If you want know to configure Log4net, see the relative posts on this site.

 

Tags:

Asp.Net

Related posts



Powered by BlogEngine.NET 1.3.1.0
Theme by Emanuele Bartolesi

About the author

Name of author Emanuele Bartolesi
I'm a senior developer and project manager.

Contact me Contact me

Calendar

<<  December 2008  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in

Download Day 2008