tbe*_*nin 6 c# asp.net msbuild logging tracelistener
我们有一个自定义TraceListener(继承自System.Diagnostics.TraceListener),我们将其用于ASP.NET Web应用程序日志记录.它一直很好 - 没有问题.然后突然间它停止在我们的开发环境中工作(TraceListener.TraceEvent()停止激活).我们感到困惑的是它为什么停止工作.我们在代码中真正做出的唯一更改是添加了更多构建配置(Dev,Test,Stage,Prod).之前,它只有Debug和Release.
我注意到当我在本地测试使用Debug配置构建时,TraceListener.TraceEvent()被触发就好了.当我切换到另一个构建配置(即测试)时,则不再触发TraceEvent().这是我的网站.csproj文件的片段:
<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>
Run Code Online (Sandbox Code Playgroud)
我不确定为什么切换构建配置似乎会关闭我们的日志记录.谁能指出我正确的方向?
找出问题所在.我调用System.Diagnostics.TraceSource.TraceEvent()来广播跟踪事件的代码在另一个项目中.我需要通过以下方式启用对该项目的跟踪:
<DefineConstants>TRACE</DefineConstants>
Run Code Online (Sandbox Code Playgroud)
我错误地认为我需要关注的是主要的目标项目(即Web项目).现在有意义了 - 调用System.Diagnostics.TraceSource.TraceEvent()的项目/程序集必须启用跟踪(通过目标构建配置的项目属性)来广播这些跟踪.然后您的跟踪侦听器可以听到它们.:)