WCF Hosted Console Does Not Track

I wrote a simple service contract ( IServiceObject ) and then executed it ( ServiceObject ). I place it in the ServiceHost object that is contained in the console application. In one of my OperationContract methods, I call Trace.WriteLine(...) . I also call Console.WriteLine(...) . In the console application before and after I Open() ServiceHost I call Trace.WriteLine(...) and Console.WriteLine(...) .

Tracing is set to autorun and has 2 listeners ( TextWriterTraceListener and ConsoleTraceListener ). When the console application starts, all Trace and Console WriteLine() calls are written to the appropriate logs. That way, the Trace call will be written to my text file and to my console, and the Console call will be written to my console.

When my client application (standalone application) calls the OperationContract method, only calls to Console.WriteLine(...) inside it are displayed on the console screen. The call to Trace.WriteLine(...) not written to the console screen or text file.

When I request (from the OperationContract method) for trace statistics (displaying them on the console using Console.WriteLine(...) ), I am told that there are 2 listeners in Trace (Text and Console) and that autoflush is on.

Does anyone know why my calls to Trace.WriteLine(...) cannot be recorded by any of the listeners only from the OperationContract method? Are there any specific attributes that I need to decorate my ServiceObject class? Are there any settings that may be missing somewhere? It seems to me that the trace is configured correctly, since it works everywhere except from my OperationContract methods ...

This seems to be a problem, my shared library that only contains my OperationContract and its implementation:

IServiceObject.cs

 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); } } 

ServiceObject.cs

 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; } } } 

Shared.csproj (which, I suspect, is the culprit, but not sure why):

 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>8.0.30703</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{23F9A333-9CC8-43FA-8A01-06BEA8B9D0E6}</ProjectGuid> <OutputType>Library</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>Shared</RootNamespace> <AssemblyName>SharedTest</AssemblyName> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <TargetFrameworkProfile /> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <PlatformTarget>x86</PlatformTarget> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> <DebugSymbols>true</DebugSymbols> <OutputPath>bin\x86\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <DebugType>full</DebugType> <PlatformTarget>x86</PlatformTarget> <CodeAnalysisLogFile>bin\Debug\Shared.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile> <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> <ErrorReport>prompt</ErrorReport> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets> <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> <OutputPath>bin\x86\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <Optimize>true</Optimize> <DebugType>pdbonly</DebugType> <PlatformTarget>x86</PlatformTarget> <CodeAnalysisLogFile>bin\Release\Shared.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile> <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> <ErrorReport>prompt</ErrorReport> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets> <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules> </PropertyGroup> <ItemGroup> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.ServiceModel" /> <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> <Compile Include="Class1.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- 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. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project> 

I built a new console console application to host a new shared library and a new client console application to connect to it and had no problems. When I imported this project as a shared library (above), Trace did not work, which was found in ServiceObject.cs. Any new ideas?

+4
source share
2 answers

This article describes how to enable and configure tracers / sources for WCF. There are several parts, and if you skip some of them, I expect the trace will not work.

+1
source

You have tried WCF Trace View Services . See if this gives you any help.

0
source

Source: https://habr.com/ru/post/1379587/


All Articles