Write to event log with Perl

Perl implements most of the functionality available from the Win32 API for the Windows event log. It can also fully leverage insertion strings.

use strict; use Win32::EventLog; # Call this function to log an event sub logMessage { my ($eventID, $eventType, @eventDetails) = @_; my $evtHandle = Win32::EventLog->new(“Your Software Application”); my %eventProperties; # Category is optional, specify only if message file contains entries for categories $eventProperties{Category} = 0; $eventProperties{EventID} = $eventID; $eventProperties{EventType} = $eventType; $eventProperties{Strings} = join("\0", @eventDetails); $evtHandle->Report(\%eventProperties); $evtHandle->Close; } # This is what you would use in your scripts to log to the event log. The insertion strings # are passed as an array, so even if you only have one string, you would need to pass it # within brackets (“This is my message”) as the last parameter logMessage(100, EVENTLOG_INFORMATION_TYPE, (“Database Backup”, “Monitoring Database”, “Complete”)); logMessage(102, EVENTLOG_INFORMATION_TYPE, (“Step 1/3 Complete”));