Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WCF Silverlight C#4.0
Hello friends ,
please tell me how can I write log file in wcf for erros and exceptions.
 
 <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 29-Jul-12 22:18pm
Edited 29-Jul-12 23:31pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try this in web.config where the services are configured.
<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.

 
Sample:
 
<behavior name="UtilityServiceBehavior">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="true" />
       </behavior>
  Permalink  
v2
Comments
Sangramsingh Pawar at 30-Jul-12 3:29am
   
I tried this but log file not generated
Santhosh Kumar J at 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 at 30-Jul-12 3:34am
   
updated solution for servicebehavior
Sangramsingh Pawar at 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 at 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
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 31 Jul 2012
Copyright © CodeProject, 1999-2014
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