Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Custom TraceListener.TraceEvent not firing

We have a custom TraceListener (inherited from System.Diagnostics.TraceListener) which we use for our ASP.NET web application logging. It's been working great - no issues. Then all the sudden it stopped working in our dev environment (TraceListener.TraceEvent() stopped firing). We are baffled as to why it stopped working. The only changes we really made in code was added more build configurations (Dev, Test, Stage, Prod). Before, it only had Debug and Release.

I notice that when I test locally having built using the Debug configuration, TraceListener.TraceEvent() is fired just fine. When I switch to another build configuration (i.e. Test), then TraceEvent() is never fired anymore. Here's a snippet of my web .csproj file:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <DebugSymbols>true</DebugSymbols>
  <DebugType>full</DebugType>
  <Optimize>false</Optimize>
  <OutputPath>bin\</OutputPath>
  <DefineConstants>TRACE;DEBUG;SkipPostSharp</DefineConstants>
  <ErrorReport>prompt</ErrorReport>
  <WarningLevel>4</WarningLevel>
  <ExcludeGeneratedDebugSymbol>false</ExcludeGeneratedDebugSymbol>
  <PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Dev|AnyCPU'">
  <OutputPath>bin\</OutputPath>
  <DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Test|AnyCPU'">
  <DebugSymbols>true</DebugSymbols>
  <DebugType>full</DebugType>
  <Optimize>false</Optimize>
  <OutputPath>bin\</OutputPath>
  <DefineConstants>TRACE;DEBUG;SkipPostSharp</DefineConstants>
  <ErrorReport>prompt</ErrorReport>
  <WarningLevel>4</WarningLevel>
  <ExcludeGeneratedDebugSymbol>false</ExcludeGeneratedDebugSymbol>
  <PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Stage|AnyCPU'">
  <OutputPath>bin\</OutputPath>
  <DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Prod|AnyCPU'">
  <OutputPath>bin\</OutputPath>
  <DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
  <OutputPath>bin\</OutputPath>
  <DefineConstants>TRACE</DefineConstants>
</PropertyGroup>

I'm not sure why switching build configurations seems to turn off our logging. Can anyone point me in the right direction?

like image 582
tbehunin Avatar asked Jan 25 '13 18:01

tbehunin


1 Answers

Figured out the issue. My code which called System.Diagnostics.TraceSource.TraceEvent() to broadcast trace events was in another Project. I needed to enable tracing on THAT project via:

<DefineConstants>TRACE</DefineConstants>

I mistakenly assumed that all I needed to focus on was the main target project (i.e. the Web project). It makes sense now - the project/assembly which calls the System.Diagnostics.TraceSource.TraceEvent() must have tracing enabled (via the project properties for the targeted build configuration) to broadcast those traces. Then your trace listeners can hear them. :)

like image 90
tbehunin Avatar answered Oct 17 '22 21:10

tbehunin