Custom Flags

Oct 5, 2009 at 11:54 PM

Hi,

Thanks a ton for putting this together. This is a great project.

Quick question: Is there any way for me to create custom flags that I can pass to EtwTrace.Trace()? In my driver I am of course able to use WPP to specify arbitrary flags.

Thanks,
Matt

P.S. I am also having the same problem listed on another thread where I was unable to get NTrace working with an existing project no matter what I did. I ended up just creating a dedicated tracing library to work around the issue.

 

Coordinator
Oct 6, 2009 at 2:22 AM

Hi, Matt-

The NTrace library does in fact support customizable flags; however, the preprocessor needs a little more work to fully support that feature. We can bump the priority on it a bit.That being said, one of the things NTrace *sorely* lacks is a VS-integrated UI for configuring features such as this, as well as things like the provider ID and trace helper class name.

Can you paste a sample .csproj that demonstrates the issue you're seeing? If you're referencing the 1.0 framework, you need to replace the Microsoft.CSharp.Targets reference with the path to NTrace.CSharp.Targets (should be "$(MSBuildExtensionsPath)\NTrace\v1.0\NTrace.CSharp.targets"). If it's the 1.1, you should include a new Imports element *after* the Microsoft.CSharp.Targets reference with the path to the 1.1 framework (should be "$(MSBuildExtensionsPath)\NTrace\v1.1\NTrace.CSharp.targets").

-Andy

Oct 6, 2009 at 5:22 PM

Regarding the flags, I would be more than happy to specify configuration without the use of the UI if that would make things easier.

Regaring the existing project issue, here is the csproj:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <EtwProviderVariable>drmserver.TraceHelper.EtwProvider</EtwProviderVariable>
    <EtwProviderId>3625D666-F6AC-4257-9EF9-0BEEB8513F97</EtwProviderId>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.30729</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{F205B6D7-E192-468D-91C8-AA89F0BB6247}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>drmserver</RootNamespace>
    <AssemblyName>drmserver</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
    <StartupObject>
    </StartupObject>
    <SignAssembly>false</SignAssembly>
    <AssemblyOriginatorKeyFile>..\..\Test Code Signing.pfx</AssemblyOriginatorKeyFile>
    <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>..\..\..\Bin\drmserver\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <NoWarn>
    </NoWarn>
    <DebugType>full</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
    <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
    <ErrorReport>prompt</ErrorReport>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <OutputPath>..\..\..\Bin\drmserver\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <NoWarn>
    </NoWarn>
    <DebugType>full</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
    <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
    <ErrorReport>prompt</ErrorReport>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="mysql.data, Version=6.0.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
      <HintPath>Lib\mysql.data.dll</HintPath>
    </Reference>
    <Reference Include="NTrace, Version=1.0.17.0, Culture=neutral, PublicKeyToken=e903e026521806f6, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>C:\Program Files (x86)\NTrace\NTrace.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.configuration" />
    <Reference Include="System.Core">
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.DirectoryServices" />
    <Reference Include="System.Web.Extensions">
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Xml.Linq">
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Data.DataSetExtensions">
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Security.cs" />
    <Compile Include="ConnectionManager.cs" />
    <Compile Include="Database\DbCore.cs" />
    <Compile Include="Database\IDrmDatabase.cs" />
    <Compile Include="Database\MySql.cs" />
    <Compile Include="Dispatch.cs" />
    <Compile Include="DispatchLookaside.cs" />
    <Compile Include="DrmConfigure.cs" />
    <Compile Include="MessageHandler.cs" />
    <Compile Include="Nanny.cs" />
    <Compile Include="Operator.cs" />
    <Compile Include="OperatorWorker.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="RmsCryptoServer.cs" />
    <Compile Include="RunningStatistics.cs" />
    <Compile Include="ServerListener.cs" />
    <Compile Include="ServiceCore.cs" />
    <Compile Include="Session.cs" />
    <Compile Include="Switchboard.cs" />
    <Compile Include="..\..\Common\Windows\ImpersonateUtil.cs" />
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework Client Profile</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
      <Visible>False</Visible>
      <ProductName>.NET Framework 2.0 %28x86%29</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.0 %28x86%29</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
      <Visible>False</Visible>
      <ProductName>Windows Installer 3.1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\Common\drmcommon\drmcommon.csproj">
      <Project>{64997566-6E73-451B-B1C9-0DFE6B413C53}</Project>
      <Name>drmcommon</Name>
    </ProjectReference>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildExtensionsPath)\NTrace\v1.1\NTrace.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
  <PropertyGroup>
    <PostBuildEvent>
    </PostBuildEvent>
  </PropertyGroup>
</Project>

 

As far as I can tell the correct tools are not being invoked, here is the build output:

6>C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /platform:AnyCPU /errorreport:prompt /define:DEBUG;TRACE /reference:H:\Pikewerks\Bin\drmcommon\Debug\drmcommon.dll /reference:Lib\mysql.data.dll /reference:"C:\Program Files (x86)\NTrace\NTrace.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.configuration.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.DirectoryServices.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Web.Extensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /out:obj\Debug\drmserver.dll /target:library /warnaserror+ Security.cs ConnectionManager.cs Database\DbCore.cs Database\IDrmDatabase.cs Database\MySql.cs Dispatch.cs DispatchLookaside.cs DrmConfigure.cs MessageHandler.cs Nanny.cs Operator.cs OperatorWorker.cs Properties\AssemblyInfo.cs RmsCryptoServer.cs RunningStatistics.cs ServerListener.cs ServiceCore.cs Session.cs Switchboard.cs ..\..\Common\Windows\ImpersonateUtil.cs

6>ServiceCore.cs(67,13): warning CS0103: The name 'EtwTrace' does not exist in the current context

6>C:\Program Files (x86)\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(132,5): error MSB3021: Unable to copy file "obj\Debug\drmserver.pdb" to "obj\Trace\drmserver.pdb". Could not find file 'obj\Debug\drmserver.pdb'.

6>Done building project "drmserver.csproj" -- FAILED.

 

Coordinator
Oct 6, 2009 at 6:59 PM

Ah! I believe I see the issue; you need to ensure that your Trace Helper class plus any files that include NTrace instrumentation are set to use the "Instrument" build action. You can set this in the Properties grid for the files, or by changing the .csproj XML to use the Instrument element instead of Compile.

Coordinator
Oct 6, 2009 at 7:00 PM

... and mea maxima culpa; the instructions for adding support to an existing project did not include this step.

Oct 6, 2009 at 7:13 PM

That fixed it. Thanks!

Another minor Q: It seems that every time there is a build a new temporary file gets created in the "Trace" directory. Is there any way to get the old temporary files cleaned up when a new build is done?