Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2008

Tip: Looking for answers? Try searching our database.

log4Net problem in WCF services

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe Bloggs - 03 Apr 2008 12:18 GMT
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
Marc Gravell - 03 Apr 2008 12:55 GMT
Well, what does the exception say? And it's InnerException etc?

Marc
Joe Bloggs - 07 Apr 2008 07:44 GMT
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

> Well, what does the exception say? And it's InnerException etc?
>
> Marc

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.