static void CreateEventSourceSample(string sourceName, string logName, string messageFile)
        {
            // Create the event source if it does not exist.
            if (!System.Diagnostics.EventLog.SourceExists(sourceName))
            {
                EventSourceCreationData mySourceData = new EventSourceCreationData(sourceName, logName);

                // Set the message resource file that the event source references.
                // All event resource identifiers correspond to text in this file.
                if (!System.IO.File.Exists(messageFile))
                {
                    Console.WriteLine("Input message resource file does not exist - {0}",
                                      messageFile);
                    messageFile = "";
                }
                else
                {
                    // Set the specified file as the resource
                    // file for message text, category text, and
                    // message parameter strings.

                    mySourceData.MessageResourceFile   = messageFile;
                    mySourceData.CategoryResourceFile  = messageFile;
                    mySourceData.CategoryCount         = CategoryCount;
                    mySourceData.ParameterResourceFile = messageFile;

                    Console.WriteLine("Event source message resource file set to {0}",
                                      messageFile);
                }

                Console.WriteLine("Registering new source for event log.");
                System.Diagnostics.EventLog.CreateEventSource(mySourceData);
            }
            else
            {
                // Get the event log corresponding to the existing source.
                logName = System.Diagnostics.EventLog.LogNameFromSourceName(sourceName, ".");
            }

            // Register the localized name of the event log.
            // For example, the actual name of the event log is "myNewLog," but
            // the event log name displayed in the Event Viewer might be
            // "Sample Application Log" or some other application-specific
            // text.
            System.Diagnostics.EventLog myEventLog = new System.Diagnostics.EventLog(logName, ".", sourceName);

            if (messageFile.Length > 0)
            {
                myEventLog.RegisterDisplayName(messageFile, 5001);
            }
        }
        protected override void OnAfterInstall(System.Collections.IDictionary savedState)
        {
            // Register display name for event log.
            using (var eventLog = new EventLog(ServerService.EventLogName, ".",
                ServerService.EventSourceName))
            {
                var messagesFileName = Path.Combine(Path.GetDirectoryName(this.Context.Parameters
                    ["assemblypath"]), "EventLogMsgs.dll");

                eventLog.RegisterDisplayName(messagesFileName, 5001);
            }

            base.OnAfterInstall(savedState);
        }