首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.Net自定义TraceListener.TraceEvent未触发

.Net自定义TraceListener.TraceEvent未触发
EN

Stack Overflow用户
提问于 2013-01-26 02:18:03
回答 1查看 1.2K关注 0票数 6

我们有一个自定义的TraceListener (继承自System.Diagnostics.TraceListener),用于我们的ASP.NET web应用程序日志记录。它工作得很好--没有问题。然后,它突然停止在我们的开发环境中工作(TraceListener.TraceEvent()停止触发)。我们对它为什么停止工作感到困惑。我们真正在代码中做的唯一更改是添加了更多的构建配置(Dev,Test,Stage,Prod)。以前,它只有Debug和Release。

我注意到,在使用Debug配置进行本地测试时,TraceListener.TraceEvent()可以很好地触发。当我切换到另一个构建配置(即测试)时,就再也不会触发TraceEvent()了。以下是我的web .csproj文件的一个片段:

代码语言:javascript
复制
<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>

我不确定为什么切换构建配置似乎会关闭我们的日志。有谁能给我指个方向吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-29 00:36:06

弄清楚了问题所在。我的代码是在另一个项目中调用System.Diagnostics.TraceSource.TraceEvent()来广播跟踪事件的。我需要通过以下方式启用对该项目的跟踪:

代码语言:javascript
复制
<DefineConstants>TRACE</DefineConstants>

我错误地认为我需要关注的只是主要的目标项目(即Web项目)。现在很有意义了-调用System.Diagnostics.TraceSource.TraceEvent()的项目/程序集必须启用跟踪(通过目标构建配置的项目属性)才能广播这些跟踪。这样,您的跟踪侦听器就可以听到它们。:)

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14527942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档