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?
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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With