Click here to Skip to main content
12,511,061 members (63,772 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# WCF Silverlight C#4.0
Hello friends ,
please tell me how can I write log file in wcf for erros and exceptions.

        <binding name="BasicHttpBinding_svc_CRUD"
                 maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
                 receiveTimeout="00:40:00" openTimeout="00:40:00"
                 closeTimeout="00:40:00" sendTimeout="00:40:00">
          <readerQuotas maxDepth="2147483647"
              maxStringContentLength="2147483647" maxArrayLength="2147483647"
              maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="None"/>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" ignoreExtensionDataObject="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
      <service name="wcfsvc_master.Session">
        <endpoint address="" binding="basicHttpBinding" contract="wcfsvc_master.ISession" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      <service name="wcfsvc_master.svc_CRUD">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_svc_CRUD"
        contract="wcfsvc_master.Isvc_CRUD" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          <timeouts closeTimeout="00:15:00" openTimeout="00:10:00" />
      <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_svc_CRUD"
     contract="wcfsvc_master.Isvc_CRUD" />
    <modules runAllManagedModulesForAllRequests="true" />
      <source name="System.ServiceModel.MessageLogging">
          <add name="messages"
          initializeData="C:\logs\messages.svclog" />
Posted 29-Jul-12 21:18pm
Updated 29-Jul-12 22:31pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

try this in web.config where the services are configured.
      <source name="System.ServiceModel" switchValue="Verbose,ActivityTracing" propagateActivity="true">
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type=""/>
          <add name="ServiceModelTraceListener">
            <filter type=""/>
      <add initializeData="C:\\Users\\santhosh.kumar\\Desktop\\LS Evaluations\\Logs" type="System.Diagnostics.XmlWriterTraceListener, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
        <filter type=""/>

and in your service behaviors add the below line.
Sangramsingh Pawar 30-Jul-12 3:29am
I tried this but log file not generated
Santhosh Kumar J 30-Jul-12 3:32am
Did you map the correct path? And do you have try catch blocks in your methods?
Also each of your service behaviors, add this
servicedebug includeexceptiondetailinfaults="true"
Santhosh Kumar J 30-Jul-12 3:34am
updated solution for servicebehavior
Sangramsingh Pawar 30-Jul-12 4:33am
I updated my web config as shown above. Also I used try catch block for service methods
Santhosh Kumar J 30-Jul-12 4:35am
Still not able to? Check in Debug mode . also for the log file path give permissions to iis users.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 31 Jul 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100