In a basic .NET web service (asmx) which I am building locally, I’m trying to log using Log4NET to a file. This works fine if I fire up debugging mode in Visual Studio and test the service using the wsdl/test pages provided. But if I try using a separate client (I made a C# console app to call the service), I see the expected response, but get NO logging.
(The separate client code is listed below. I had to import a reference to the built DLL of the web service.)
I’m a bit new to this, but I speculate the issue is because outside of the VS server or IIS (which I am stuck without), Global.asax is not used (which contains my initialization command for logging). But I need to test from an external client. How can I get Global.asax to initialize from the client application perspective, or how can I avoid needing to? Does this sound like it would solve my logging issue?
Global.asax in my web service project contains this statement:
protected void Application_Start(object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
}
And my separate client (console) application looks like this:
static void Main(string[] args)
{
MyWebService proxy = new MyWebService();
MyWebService.Request request = new MyWebService.Request();
request.Type = "Test";
MyWebService.Response response = proxy.GetResponse(request);
Console.WriteLine("RESPONSE CODE: " + response.StatusCode);
Console.WriteLine("RESPONSE MSG: " + response.StatusMessage);
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
}
I’m also unclear how I would change this console app to reference the Visual Studio server instance (ex: localhost:1583/MyWebService.asmx?op=GetResponse) instead of creating a proxy instance of the web service. I think that would also do the trick, since the Visual Studio server utilizes Global.asax, no?
The simpler way
would be to move the log4net initialization inside
static void Main:Don’t forget to include
log4netconfiguration inapp.configfile of your new host.The better way
would be to move your service to separate project (it is already so, right?) so it is complied into it’s own assembly. Than apply
attribute to the
assemlyInfo.cs. Refer to log4net configuration manual for details (search for wordassemblyon the page). This way is better, because you’ll not have to add thatinto the initialization of all host environments you have.
But make sure you have your log4net configuration in
app.config,web.configor whatever configuration file you have.