log4Net problem in WCF services

J

Joe Bloggs

Hi,

I am experiencing problem using log4Net within a WCF services. In my
service implementation, I would like to log messages using log4Net. I
host my service inside and IIS and hence my log4net config sits inside
the web.config file.

Here is a sample of my code:

-----------

[ServiceBehavior(Name = "Test", Namespace = "http://
EntDocGenWCFService.ServiceContracts/2008/03")]
public class Test : EntDocGenWCFService.ServiceContracts.ITest
{
// seems to throw an exception here
private static readonly ILog log =
LogManager.GetLogger(typeof(Test));

#region ITest Members

public Test()
{
XmlConfigurator.Configure();
}

public string Method1(string request)
{
log.Info(string.Format("Response to Request:{0} ",
request));
Trace.Write("Testing - using Trace appender");
return String.Format("Response to Request:{0} ", request);
}

#endregion
}

--------------------
Now it seems strange that instantiation a static instance of the
logger class is throwing me an exception. I desperately need help.
Why is that an issue instantiation a static log4Net logger in this
fashion? What is in WCF running instant that can throw an exception
like this? BTW, this happens in VS.Net environment. I haven't tried
running this outside on a server.

Thanks in advanced
 
J

Joe Bloggs

HI Marc,

I am getting this exception at the client side:

Server stack trace:
at
System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message
reply, MessageFault fault, String action, MessageVersion version,
FaultConverter faultConverter)
at
System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime
operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins,
Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins,
Object[] outs)
at
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
message)

Exception rethrown at [0]:
at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at EntDocGenWCFService.Client.TestService.ITest.Method1(String
request)
at EntDocGenWCFService.Client.TestService.TestClient.Method1(String
request) in D:\My Projects\EntDocGenWCFService\Tests
\EntDocGenWCFService.Client\Service References\TestService.cs:line 60
at EntDocGenWCFService.Client.MainForm.btnTestService_Click(Object
sender, EventArgs e) in D:\My Projects\EntDocGenWCFService\Tests
\EntDocGenWCFService.Client\MainForm.cs:line 34
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at EntDocGenWCFService.Client.Program.Main() in D:\My Projects
\EntDocGenWCFService\Tests\EntDocGenWCFService.Client\Program.cs:line
16
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


Inner exception is null.

It seems like an exception is thrown by WCF during or before the
executing of the instantiation of the Logger (GetLogger method). The
try and catch in the service did nothing.

Thanks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top