15

This is an intentional semi-duplicate of How do you create an event log source using WiX and WIX: Create EventSource using .NET message file.

My first question is, does it really have to be so complicated? Isn't there some way to simply specify to WiX, "my program is a .Net program, and it needs to write to the event log - please do the necessary setup"?

OK, assuming that isn't possible, I'd like to receive any recommendations for the necessary WiX statements to make it work, irrespective of which version of .Net Framework is installed, and irrespective of whether it is a 32 or 64-bit system. After all, most of my .Net programs are able to run on .Net 2.0 or later, and on either 32 or 64-bit, so it shouldn't matter.

Final question: Is there any way to make it future-proof? It would be nice if the MSI files I generate today will still work in five years, even if .Net CLR 2.0 and 4.0 have both been relegated to the dustbin in Windows 11 or whatever it's called then.

Community
  • 1
  • 1
RenniePet
  • 11,420
  • 7
  • 80
  • 106
  • 1
    I agree with you. It is very complicated to make this. I have a setup that is more simple (only targeted .NET 4) - and it is still complicated: 32bit/64bit OS + .NET 4 client profile/.NET 4 full. I have a working solution - but it is not future proof - and the code is not very readable. – Morten Frederiksen Sep 15 '12 at 13:46
  • 1
    Morten, thanks for your comment. I'd appreciate it if you posted your current solution as an answer to my question, thanks. – RenniePet Sep 15 '12 at 16:19

1 Answers1

37

As requested. A solution that works on .NET 4 full and .NET 4 client profile using UtilExtension:

1) Add these PropertyRef's:

<PropertyRef Id="NETFRAMEWORK40FULLINSTALLROOTDIR"/>
<PropertyRef Id="NETFRAMEWORK40FULLINSTALLROOTDIR64"/>
<PropertyRef Id="NETFRAMEWORK40CLIENTINSTALLROOTDIR"/>
<PropertyRef Id="NETFRAMEWORK40CLIENTINSTALLROOTDIR64"/>

2) 32 bit part:

<!-- Event Source creation for 32bit OS with .NET 4 Full-->
<Component Id="CreateEventSource32BitFullNet4" Guid="your-guid-here">
    <Condition><![CDATA[NETFRAMEWORK40FULLINSTALLROOTDIR AND NOT VersionNT64]]></Condition>
    <CreateFolder/>
    <!-- Create an Event Source -->
    <Util:EventSource
          xmlns:Util="http://schemas.microsoft.com/wix/UtilExtension"
          Name="YOUR APP NAME"
          Log="Application"
          EventMessageFile="[NETFRAMEWORK40FULLINSTALLROOTDIR]EventLogMessages.dll"/>
</Component>

<!-- Event Source creation for 32bit OS with .NET 4 Client Profile-->
<Component Id="CreateEventSource32BitClientNet4" Guid="your-guid-here">
    <Condition><![CDATA[NETFRAMEWORK40CLIENTINSTALLROOTDIR AND NOT VersionNT64]]></Condition>
    <CreateFolder/>
    <!-- Create an Event Source -->
        <Util:EventSource
          xmlns:Util="http://schemas.microsoft.com/wix/UtilExtension"
          Name="YOUR APP NAME"
          Log="Application"
          EventMessageFile="[NETFRAMEWORK40CLIENTINSTALLROOTDIR]EventLogMessages.dll"/>
</Component>

3) 64 bit part:

<!-- Event Source creation for 64bit OS with .NET 4 Full -->
<Component Id="CreateEventSource64BitFullNet4" Guid="your-guid-here">
    <Condition><![CDATA[NETFRAMEWORK40FULLINSTALLROOTDIR64 AND VersionNT64]]></Condition>
    <CreateFolder/>
    <!-- Create an Event Source -->
    <Util:EventSource
          xmlns:Util="http://schemas.microsoft.com/wix/UtilExtension"
          Name="YOUR APP NAME"
          Log="Application"
          EventMessageFile="[NETFRAMEWORK40FULLINSTALLROOTDIR64]EventLogMessages.dll"/>
</Component>

<!-- Event Source creation for 64bit OS with .NET 4 Client Profile -->
<Component Id="CreateEventSource64BitClientNet4" Guid="your-guid-here">
    <Condition><![CDATA[NETFRAMEWORK40CLIENTINSTALLROOTDIR64 AND VersionNT64]]></Condition>
    <CreateFolder/>
    <!-- Create an Event Source -->
    <Util:EventSource
          xmlns:Util="http://schemas.microsoft.com/wix/UtilExtension"
          Name="YOUR APP NAME"
          Log="Application"
          EventMessageFile="[NETFRAMEWORK40CLIENTINSTALLROOTDIR64]EventLogMessages.dll"/>
</Component>
David Clarke
  • 12,888
  • 9
  • 86
  • 116
Morten Frederiksen
  • 5,114
  • 1
  • 40
  • 72
  • Morten, does this mean that the logs being generated by the installer will be logged under whatever source we mention as opposed to the MsiInstaller source it logs under by default? – randomuser15995183 Oct 15 '16 at 13:39
  • No, randomuser25995183, this log sources are being created for the installed application to use it for its logging in the system logs. – Ravior Feb 02 '18 at 12:12