Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello friends ,
please tell me how can I write log file in wcf for erros and exceptions.

HTML
 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <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"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
    <services>
      <service name="wcfsvc_master.Session">
        <endpoint address="" binding="basicHttpBinding" contract="wcfsvc_master.ISession" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <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" />
        <host>
          <timeouts closeTimeout="00:15:00" openTimeout="00:10:00" />
        </host>

      </service>
    </services>
    <client>
      <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_svc_CRUD"
     contract="wcfsvc_master.Isvc_CRUD" />
    </client>
    <diagnostics>
      <messageLogging
            logEntireMessage="true"
            logMalformedMessages="false"
            logMessagesAtServiceLevel="true"
            logMessagesAtTransportLevel="false"
            maxMessagesToLog="3000"
            maxSizeOfMessageToLog="2000"/>
    </diagnostics>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="messages"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="C:\logs\messages.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
<
Posted
Updated 29-Jul-12 22:31pm
v2

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


and in your service behaviors add the below line.
<servicedebug includeexceptiondetailinfaults="true">

Sample:

XML
<behavior name="UtilityServiceBehavior">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="true" />
       </behavior>
 
Share this answer
 
v2
Comments
Sangramsingh Pawar 30-Jul-12 3:29am    
I tried this but log file not generated
Santhosh Kumar Jayaraman 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 Jayaraman 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 Jayaraman 30-Jul-12 4:35am    
Still not able to? Check in Debug mode . also for the log file path give permissions to iis users.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900