【问题标题】:System.diagnostics logging issue + Wix application name changeSystem.diagnostics 日志记录问题 + Wix 应用程序名称更改
【发布时间】:2013-03-28 06:32:53
【问题描述】:

在我的应用程序中,我已将 Trace 侦听器配置如下

“HelloWorld”是我的 AssemblyName命名空间

<system.diagnostics>
<sources>
  <source name="DebugCategory" switchName="DebugSwitch" switchType="System.Diagnostics.SourceSwitch">
    <listeners>
      <remove name="Default"/>
      <!-- Add the listeners below -->
      <add name="LogFile"/>
    </listeners>
  </source>
</sources>
<sharedListeners>
 <add name="Console" type="System.Diagnostics.ConsoleTraceListener" initializeData="true"/>
 <add name="LogFile" type="HelloWorld.Diagnostics.FileLogTraceListener, HelloWorld" initializeData="HelloWorld.log" traceOutputOptions="DateTime" cycle="Month"/>
</sharedListeners>

在使用 WIX 创建安装程序时,在我的 WIX 文件中,我会将 Target exe 文件从“HelloWorld.exe”制作为 “MyWorld.exe”,如下所示

  <Component Id="MyWorld.exe" Guid="*">
    <File Id="MyWorld.exe" Name="MyWorld.exe"
        DiskId="1" Source="HelloWorld.exe" />
    <Shortcut Id="HelloWorld.menu.exe" Name="Hello world application" Directory="McnMenu" Advertise="yes" WorkingDirectory="INSTAL32LLOCATION" />
  </Component>

由于 EXE 名称发生变化,Tracelistener 不会创建日志文件。

目标名称应该是“Myworld.exe”,如果我将文件元素还原为

     <File Id="HelloWorld.exe" Name="HelloWorld.exe" /> 

效果很好

谁能帮帮我。

【问题讨论】:

    标签: wix wix3.6 system.diagnostics tracelistener


    【解决方案1】:

    在 .config 文件的这一行中:

    <add name="LogFile" type="HelloWorld.Diagnostics.FileLogTraceListener, HelloWorld" initializeData="HelloWorld.log" traceOutputOptions="DateTime" cycle="Month"/>
    

    你有type="HelloWorld.Diagnostics.FileLogTraceListener, HelloWorld"。那是对程序集中的类的引用。程序集名称(文件名)是逗号后面的部分。因此,您的 .config 文件需要将程序集(在您的情况下为可执行文件)命名为“HelloWorld”。

    要修复,您可以保留文件名 HelloWorld.exe(如您所见)或更改 .config 文件,如下所示:

    <add name="LogFile" type="HelloWorld.Diagnostics.FileLogTraceListener, MyWorld" initializeData="HelloWorld.log" traceOutputOptions="DateTime" cycle="Month"/>
    

    注意逗号后type 中的MyWorld

    【讨论】:

    • 对我来说,将文件构建为一个名称并将其部署为另一个名称似乎是一种黑客行为。 .NET 程序集知道它们的文件名应该是什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-01
    • 2020-02-07
    • 2020-02-05
    • 2018-02-26
    相关资源
    最近更新 更多