I would like to create a log file in the Windows EventLog with numerous EventLog Sources. There is this wonderful feature in Wix that lets me do just that: the EventSource element in the WixUtilExtension dll. One thing that is missing from this element is the ability to change the default properties of the EventLog which is created with such an element. I have searched online for this problem and have come along this post on stackoverflow post:
http://stackoverflow.com/questions/2372988/how-to-change-event-log-properties-from-wix-script However, this post does not provide a solution for this problem. In conclusion the post states, that a custom action has to be written to achieve this task. I would rather refrain from writing my own custom action, if there is another possibility to achieve this. But for now, I would like to ask for advice on how to properly write such a custom action. I have come up with a solution to this problem with the following approach: - created EventSource elements. - wrote a custom action that simply sets the eventlog properties. - added a RegistryKey element. I will now post the code to each part of the approach and explain why I did it that way. The EventSource elements look like this: <Component Id="CMP_EventLogNetfx2" Guid="SOME-GUID"> <util:EventSource Name="Source1" EventMessageFile="{[NETFRAMEWORK20INSTALLROOTDIR]}EventLogMessages.dll" Log="MyLog" KeyPath="yes"/> <Condition> <![CDATA[(Installed OR NETFRAMEWORK20) AND VersionNT < 600]]> </Condition> </Component> <Component Id="CMP_EventLogNetfx4" Guid="ANOTHER-GUID"> <util:EventSource Name="Source2" EventMessageFile="{[NETFRAMEWORK20INSTALLROOTDIR]}EventLogMessages.dll" Log="MyLog" KeyPath="yes"/> <Condition> <![CDATA[(Installed OR NETFRAMEWORK40FULL) AND VersionNT >= 600]]> </Condition> </Component> I want to keep the CustomAction as simple as possible, therefore the creation of the EventLog and EventLog Source should be handled by the installer. I check for the presence of .Net Framework in order to load the correct EventLogMessages dll. The code of the CustomAction looks like this: using System; using Microsoft.Deployment.WindowsInstaller; using System.Diagnostics; namespace EvlCA { public class CustomActions { [CustomAction] public static ActionResult UpdateEventLog(Session session) { EventLog log = new EventLog("MyLog"); log.MaximumKilobytes = 2048; log.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 0); return ActionResult.Success; } } } All I'm doing here, as you can see, is to set the properties of the EventLog. The funny thing is, that after the log has been installed by my installer, the eventvwr.msc snap-in displays the value "1028" for the size of the log. I don't understand why that is happening, because the ModifyOverflowPolicy method works as expected. I am very unsure, if using such a simple CustomAction is acceptable. Do I have to expand it to cover Rollback and Uninstallation? I have scheduled the CustomAction to run like this: <Product> ... <Binary Id="EvlCADLL" SourceFile="$(var.EvlCA.TargetDir)EvlCA.CA.dll" /> <CustomAction Id="CA_EvlCA" BinaryKey="EvlCADLL" DllEntry="UpdateEventLog" Execute="commit" Return="check" /> ... </Product> I am unsure about the Execute attribute. When this is set to immediate I have to create an InstallExecuteSequence element and schedule it myself. I have omitted this element because I assigned the commit value to that attribute. Is that correct, or do I have to include an InstallExecuteSequnce element anyway? To compensate for the funny value "1028" I added the following RegistryKey element: <ComponentGroup Id="UpdateEventLogRegistryValues" Directory="INSTALLFOLDER"> <Component Id="CMP_EventLogSetRegistryEntries" Guid="LAST-GUID"> <RegistryKey Root="HKLM" Key="SYSTEM\CurrentControlSet\services\eventlog\MyLog"> <RegistryValue Name="AutoBackupLogFiles" Action="write" Value="0" Type="integer" KeyPath="yes"/> <RegistryValue Name="MaxSize" Action="write" Value="2097152" Type="integer" /> <RegistryValue Name="MaxSizeUpper" Action="write" Value="0" Type="integer" /> <RegistryValue Name="Retention" Action="write" Value="0" Type="integer" /> </RegistryKey> </Component> </ComponentGroup> This results in the value I actually desired: 2048. It has to be written like that, because according to this post http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/setting-hex-value-for-DWORD-in-registry-td697623.html the Registry table only stores decimal values. The problem is that altering the registry has no effect until the machine is restarted. But that is something I can live with, as long as my custom action sets the modifyoverflowpolicy correctly. I would really love to see an extension to the WixUtilExtension library which provides an EventLog element with the Attributes ModifyOverflowPolicy, MaximumKilobytes, MinimumRetentionDays... essentially all the Properties you can set for an EventLog object from the System.Diagnostics namespace. Thanks for your help. ------------------------------------------------------------------------------ Try New Relic Now & We'll Send You this Cool Shirt New Relic is the only SaaS-based application performance monitoring service that delivers powerful full stack analytics. Optimize and monitor your browser, app, & servers with just a few lines of code. Try New Relic and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr _______________________________________________ WiX-users mailing list WiX-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wix-users