Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Trace Logging Not Producing Log Files

Tags:

c#

wcf

WCF Trace logging appears to not be working in one of my wcf windows services. I've used this same configuration in other services and it has worked in the past. I'm stumped at this point. Here is the configuration that I have:

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging"
              switchValue="Information, ActivityTracing">
        <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData="C:\ProgramData\Bastian Software\Logs\ExactaManifest\Messages.svclog"  />
        </listeners>
      </source>
      <source name="System.ServiceModel"
                switchValue="Information, ActivityTracing">
        <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData="C:\ProgramData\Bastian Software\Logs\ExactaManifest\WCF.svclog"  />
        </listeners>
      </source>
    </sources>

    <trace autoflush="true" />
  </system.diagnostics>
  <system.serviceModel>
    <diagnostics performanceCounters="All">
      <messageLogging
         logMessagesAtTransportLevel="true"
         logMessagesAtServiceLevel="false"
         logMalformedMessages="true"
         logEntireMessage="true"
         maxSizeOfMessageToLog="2147483647" maxMessagesToLog="25000" />
    </diagnostics>
  </system.serviceModel>

</configuration>

It doesn't appear to be a permissions issue because I manually created a folder and file with the same user that the service is running under. Also I do see the following in the event viewer related to this wcf trace logging:

enter image description here

Any suggestions?

like image 923
Cole W Avatar asked Apr 30 '14 14:04

Cole W


People also ask

How do I check WCF logs?

Viewing Event Logs. Event logging is enabled automatically by default, and there is no mechanism to disable it. Events logged by WCF can be viewed using the Event Viewer. To launch this tool, click Start, click Control Panel, double-click Administrative Tools, and then double-click Event Viewer.

How do I create a .svclog file in WCF?

To set up, build, and run the sample Before running the Tracing and Message Logging sample, create the directory C:\logs\ for the service to write the . svclog files to. The name of this directory is defined in the configuration file as the path for the traces and messages to be logged and can be changed.

How do I enable tracing and message logging in WCF?

To activate message logging, you must add a trace listener to the System. ServiceModel. MessageLogging trace source and set attributes for the <messagelogging> element in the configuration file. The following example shows how to enable logging and specify additional options.


2 Answers

The log files will only be created if the directory specified in the configuration previously exists; it's more than just the permissions being in place to create the log file. See this note section from MSDN article:

Trace files are not created without initially creating the log directory. Make sure that the directory C:\logs\ exists, or specify an alternate logging directory in the listener configuration.

like image 187
SloppyJ03 Avatar answered Nov 02 '22 18:11

SloppyJ03


Based on your comment "it does not generate any svclogs" leads me to believe the issue is related to your permissions. If you are utilizing Windows 8 Visual Studio will need to be opened as an Administrator. If you don't, then it will not generate any trace log files.

Some other items you might check:

  • Application Pool is able to read / write to your project directory (Security Tab).
  • The service is assigned the proper Application Pool to manipulate the project directory.

I'm assuming it is either hosted through Internet Information System (IIS) or being debugged through Visual Studio. One of those two should hopefully resolve the issue.

On Microsoft's Developer Network they actually add an important note about running as an Administrator in Windows 8 due to how often it is overlooked.

like image 20
Greg Avatar answered Nov 02 '22 18:11

Greg