C# .Net自定义TraceListener.TraceEvent未启动
我们有一个自定义TraceListener(继承自System.Diagnostics.TraceListener),用于ASP.NET web应用程序日志记录。它工作得很好-没有问题。然后它突然在我们的开发环境中停止工作(TraceListener.TraceEvent()停止启动)。我们对它为什么停止工作感到困惑。我们在代码中真正做的唯一更改是添加了更多的构建配置(Dev、Test、Stage、Prod)。以前,它只有调试和发布 我注意到,当我使用调试配置在本地测试生成时,TraceListener.TraceEvent()会被很好地激发。当我切换到另一个构建配置(即测试)时,TraceEvent()将不再被激发。下面是我的web.csproj文件的一个片段:C# .Net自定义TraceListener.TraceEvent未启动,c#,asp.net,logging,msbuild,tracelistener,C#,Asp.net,Logging,Msbuild,Tracelistener,我们有一个自定义TraceListener(继承自System.Diagnostics.TraceListener),用于ASP.NET web应用程序日志记录。它工作得很好-没有问题。然后它突然在我们的开发环境中停止工作(TraceListener.TraceEvent()停止启动)。我们对它为什么停止工作感到困惑。我们在代码中真正做的唯一更改是添加了更多的构建配置(Dev、Test、Stage、Prod)。以前,它只有调试和发布 我注意到,当我使用调试配置在本地测试生成时,TraceList
<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>
真的
满的
假的
垃圾箱\
痕迹;调试;船长
促使
4.
假的
任意CPU
垃圾箱\
痕迹
真的
满的
假的
垃圾箱\
痕迹;调试;船长
促使
4.
假的
任意CPU
垃圾箱\
痕迹
垃圾箱\
痕迹
垃圾箱\
痕迹
我不知道为什么切换构建配置似乎会关闭日志记录。有人能给我指出正确的方向吗?解决了这个问题。我调用System.Diagnostics.TraceSource.TraceeEvent()来广播跟踪事件的代码位于另一个项目中。我需要通过以下方式对该项目进行跟踪:
<DefineConstants>TRACE</DefineConstants>
跟踪
我错误地认为我需要关注的只是主要目标项目(即Web项目)。现在有意义了-调用System.Diagnostics.TraceSource.TraceeEvent()的项目/程序集必须启用跟踪(通过目标生成配置的项目属性)才能广播这些跟踪。然后您的跟踪侦听器可以听到它们。:) 天哪,我刚刚花了一天半的时间来整理我的头发,真是太棒了!!!