title: Console hosted WCF service does not Trace
body: <p>I have written a simple service contract (<code>IServiceObject</code>) and then implemented it (<code>ServiceObject</code>).  I host it in a <code>ServiceHost</code> object that is contained within a console application.  Within one of my <code>OperationContract</code> methods I call <code>Trace.WriteLine(...)</code>.  I also call <code>Console.WriteLine(...)</code>.  Within the console application, before and after I <code>Open()</code> the <code>ServiceHost</code>, I call <code>Trace.WriteLine(...)</code> and <code>Console.WriteLine(...)</code>.</p>
  
  <p>Trace is set to autoflush, and has 2 listeners (<code>TextWriterTraceListener</code> and <code>ConsoleTraceListener</code>).  When the console application fires up, all Trace and Console <code>WriteLine()</code> calls are written to their respective logs.  So the Trace call will write to my text file and to my console and the Console call will write to my console.</p>
  
  <p>When my client application (a separate application) calls the <code>OperationContract</code> method, only the <code>Console.WriteLine(...)</code> calls within it are displayed on the console screen.  The <code>Trace.WriteLine(...)</code> calls are not written to the console screen or the text file.</p>
  
  <p>When I query (from within the <code>OperationContract</code> method) for the Trace stats (outputting them to the console screen with <code>Console.WriteLine(...)</code>) I am told that there are 2 listeners in Trace (Text and Console) and that autoflush is on.</p>
  
  <p>Does anyone know why my calls to <code>Trace.WriteLine(...)</code> would fail to write to either of the listeners only from within the <code>OperationContract</code> method?  Are there some specific attributes I need to decorate my <code>ServiceObject</code> class with?  Are there some settings I might be missing somewhere?  It seems to me that the Tracing is configured correctly since it works everywhere except from within my <code>OperationContract</code> methods...</p>
  
  <p>This seems to be problem, my shared library that contains only my OperationContract and its implementation:</p>
  
  <h2>IServiceObject.cs</h2>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Text;
  using System.ServiceModel;
  using System.Diagnostics;
  
  namespace SuccessEHS.Dev.Shared
  {
      [ServiceContract]
      public interface IServiceObject
      {
          [OperationContract]
          bool Test(string text);
      }
  }
  </code></pre>
  
  <h2>ServiceObject.cs</h2>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Diagnostics;
  using System.ServiceModel;
  
  namespace SuccessEHS.Dev.Shared
  {
      public class ServiceObject : IServiceObject
      {
          public bool Test(string text)
          {
              Console.Write("Testing 1");
              Trace.Write("..2");
              Console.Write("..3");
              Trace.Write("..4");
              Console.WriteLine("..5");
  
              Console.WriteLine("CW: {0}", text);
              Trace.WriteLine(string.Format("TW: {0}", text));
  
              return true;
          }
      }
  }
  </code></pre>
  
  <p><strong>Shared.csproj (which I suspect is the culprit but am not sure why):</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;PropertyGroup&gt;
      &lt;Configuration Condition=" '$(Configuration)' == '' "&gt;Debug&lt;/Configuration&gt;
      &lt;Platform Condition=" '$(Platform)' == '' "&gt;AnyCPU&lt;/Platform&gt;
      &lt;ProductVersion&gt;8.0.30703&lt;/ProductVersion&gt;
      &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
      &lt;ProjectGuid&gt;{23F9A333-9CC8-43FA-8A01-06BEA8B9D0E6}&lt;/ProjectGuid&gt;
      &lt;OutputType&gt;Library&lt;/OutputType&gt;
      &lt;AppDesignerFolder&gt;Properties&lt;/AppDesignerFolder&gt;
      &lt;RootNamespace&gt;Shared&lt;/RootNamespace&gt;
      &lt;AssemblyName&gt;SharedTest&lt;/AssemblyName&gt;
      &lt;TargetFrameworkVersion&gt;v3.5&lt;/TargetFrameworkVersion&gt;
      &lt;FileAlignment&gt;512&lt;/FileAlignment&gt;
      &lt;TargetFrameworkProfile /&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "&gt;
      &lt;DebugSymbols&gt;true&lt;/DebugSymbols&gt;
      &lt;DebugType&gt;full&lt;/DebugType&gt;
      &lt;Optimize&gt;false&lt;/Optimize&gt;
      &lt;OutputPath&gt;bin\Debug\&lt;/OutputPath&gt;
      &lt;DefineConstants&gt;DEBUG;TRACE&lt;/DefineConstants&gt;
      &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
      &lt;WarningLevel&gt;4&lt;/WarningLevel&gt;
      &lt;PlatformTarget&gt;x86&lt;/PlatformTarget&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "&gt;
      &lt;DebugType&gt;pdbonly&lt;/DebugType&gt;
      &lt;Optimize&gt;true&lt;/Optimize&gt;
      &lt;OutputPath&gt;bin\Release\&lt;/OutputPath&gt;
      &lt;DefineConstants&gt;TRACE&lt;/DefineConstants&gt;
      &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
      &lt;WarningLevel&gt;4&lt;/WarningLevel&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"&gt;
      &lt;DebugSymbols&gt;true&lt;/DebugSymbols&gt;
      &lt;OutputPath&gt;bin\x86\Debug\&lt;/OutputPath&gt;
      &lt;DefineConstants&gt;DEBUG;TRACE&lt;/DefineConstants&gt;
      &lt;DebugType&gt;full&lt;/DebugType&gt;
      &lt;PlatformTarget&gt;x86&lt;/PlatformTarget&gt;
      &lt;CodeAnalysisLogFile&gt;bin\Debug\Shared.dll.CodeAnalysisLog.xml&lt;/CodeAnalysisLogFile&gt;
      &lt;CodeAnalysisUseTypeNameInSuppression&gt;true&lt;/CodeAnalysisUseTypeNameInSuppression&gt;
      &lt;CodeAnalysisModuleSuppressionsFile&gt;GlobalSuppressions.cs&lt;/CodeAnalysisModuleSuppressionsFile&gt;
      &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
      &lt;CodeAnalysisRuleSet&gt;MinimumRecommendedRules.ruleset&lt;/CodeAnalysisRuleSet&gt;
      &lt;CodeAnalysisRuleSetDirectories&gt;;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets&lt;/CodeAnalysisRuleSetDirectories&gt;
      &lt;CodeAnalysisIgnoreBuiltInRuleSets&gt;true&lt;/CodeAnalysisIgnoreBuiltInRuleSets&gt;
      &lt;CodeAnalysisRuleDirectories&gt;;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules&lt;/CodeAnalysisRuleDirectories&gt;
      &lt;CodeAnalysisIgnoreBuiltInRules&gt;true&lt;/CodeAnalysisIgnoreBuiltInRules&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"&gt;
      &lt;OutputPath&gt;bin\x86\Release\&lt;/OutputPath&gt;
      &lt;DefineConstants&gt;TRACE&lt;/DefineConstants&gt;
      &lt;Optimize&gt;true&lt;/Optimize&gt;
      &lt;DebugType&gt;pdbonly&lt;/DebugType&gt;
      &lt;PlatformTarget&gt;x86&lt;/PlatformTarget&gt;
      &lt;CodeAnalysisLogFile&gt;bin\Release\Shared.dll.CodeAnalysisLog.xml&lt;/CodeAnalysisLogFile&gt;
      &lt;CodeAnalysisUseTypeNameInSuppression&gt;true&lt;/CodeAnalysisUseTypeNameInSuppression&gt;
      &lt;CodeAnalysisModuleSuppressionsFile&gt;GlobalSuppressions.cs&lt;/CodeAnalysisModuleSuppressionsFile&gt;
      &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
      &lt;CodeAnalysisRuleSet&gt;MinimumRecommendedRules.ruleset&lt;/CodeAnalysisRuleSet&gt;
      &lt;CodeAnalysisRuleSetDirectories&gt;;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets&lt;/CodeAnalysisRuleSetDirectories&gt;
      &lt;CodeAnalysisIgnoreBuiltInRuleSets&gt;true&lt;/CodeAnalysisIgnoreBuiltInRuleSets&gt;
      &lt;CodeAnalysisRuleDirectories&gt;;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules&lt;/CodeAnalysisRuleDirectories&gt;
      &lt;CodeAnalysisIgnoreBuiltInRules&gt;true&lt;/CodeAnalysisIgnoreBuiltInRules&gt;
    &lt;/PropertyGroup&gt;
    &lt;ItemGroup&gt;
      &lt;Reference Include="System" /&gt;
      &lt;Reference Include="System.Data" /&gt;
      &lt;Reference Include="System.ServiceModel" /&gt;
      &lt;Reference Include="System.Xml" /&gt;
    &lt;/ItemGroup&gt;
    &lt;ItemGroup&gt;
      &lt;Compile Include="Class1.cs" /&gt;
      &lt;Compile Include="Properties\AssemblyInfo.cs" /&gt;
    &lt;/ItemGroup&gt;
    &lt;Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /&gt;
    &lt;!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
         Other similar extension points exist, see Microsoft.Common.targets.
    &lt;Target Name="BeforeBuild"&gt;
    &lt;/Target&gt;
    &lt;Target Name="AfterBuild"&gt;
    &lt;/Target&gt;
    --&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>I built a new server console app to host a new shared library and a new client console app to connect to it and had no issues.  When I then imported this project as the shared library (above) the Tracing failed to work that was found in ServiceObject.cs.  Any new ideas?</p>