Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > Custom event logs, installation/creation and naming.
 

Custom event logs, installation/creation and naming.

I'm primarily using C#. I want to create a custom event log during installation of a service, and not log to the application event log.
I have read various threads, which tell me to hunt down the eventlog installer created by default fora service and remove it, which works nicely. In the following, I've changed the names to protect the guilty

My service is named "SMSAtlas". I can successfully name it and set the display name of the service.
I want the displayname of my custom eventlog to be "SMS Atlas Integration", and I want the actual file to be "SMSAIS".

The service is installed correctly, but my event log display name and file names are not what I expected.
Can anyone provide a clue as to what I'm doing wrong?

namespace SMS.AtlasIntegration
{
    [RunInstaller(true)]
    public partial class AtlasInstaller : Installer
    {
        private EventLogInstaller myEvtLogInstaller;
        private ServiceInstaller svcInstaller;
        private ServiceProcessInstaller svcProcInstaller;
        public AtlasInstaller()
        {
            InitializeComponent();
            // Add the service process installer
            svcProcInstaller = new ServiceProcessInstaller();
            svcProcInstaller.Account = ServiceAccount.LocalSystem;

            svcInstaller = new ServiceInstaller();
            svcInstaller.StartType = ServiceStartMode.Manual;
            svcInstaller.ServiceName = "SMS Atlas";
            svcInstaller.DisplayName = "SMS Atlas Integration Service";

            // Add the event log installer.
            myEvtLogInstaller = new EventLogInstaller();
            myEvtLogInstaller.Source = "SMS Atlas Integration";
            myEvtLogInstaller.Log = "SMSAIS";
            myEvtLogInstaller.UninstallAction = UninstallAction.Remove;

            Installers.Add(myEvtLogInstaller);
            Installers.Add(svcProcInstaller);
            Installers.Add(svcInstaller);

            EventLogInstaller defInstaller = null;
            foreach (Installer inst in svcInstaller.Installers)
            {
                if (inst is EventLogInstaller)
                {
                    defInstaller = inst as EventLogInstaller;
                    break;
                }
            }
            if (defInstaller != null)
            {
                svcInstaller.Installers.Remove(defInstaller);
            }
        }
    }
}<br/><br/><br/>
Regards

Steve S

Steve Spencer
SteveS_  Monday, August 17, 2009 2:00 PM

Hi Steve,

Based on my understanding, the problem you are facing is how to write the event log to a file named “SMSAIS�and the Source Name should be “SMS Atlas Integration� right?

As I can see from the code you provided, there’s no problem. But I can’t see how you write the logs from your windows service application. So I don’t know if the Source property of the EventLog is setup right.

Based on the code of this document, try to use the below method to log message, and see if you can get the desired result.


 protected override void OnStart(string[] args)
        {
            if (!EventLog.SourceExists("SMS Atlas Integration"))
            {
                // An event log source should not be created and immediately used.
                // There is a latency time to enable the source, it should be created
                // prior to executing the application that uses the source.
                // Execute this sample a second time to use the new source.
                EventLog.CreateEventSource("SMS Atlas Integration", "MyNewLog");
                Console.WriteLine("CreatingEventSource");
                Console.WriteLine("Exiting, execute the application a second time to use the source.");
                // The source is created.  Exit the application to allow it to be registered.
            }

            // Create an EventLog instance and assign its source.
         
            myLog.Source = "SMS Atlas Integration";

            // Write an informational entry to the event log.    
            myLog.WriteEntry("service is started");
            
        }

        protected override void OnStop()
        {
            myLog.WriteEntry("service is stoped");

        }

If I have misunderstood you or the problem can’t be solved, please feel free to let me know.

Best regards,

Bruce Zhou

MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bruce.Zhou  Tuesday, August 18, 2009 10:07 AM

Hi Steve,

Based on my understanding, the problem you are facing is how to write the event log to a file named “SMSAIS�and the Source Name should be “SMS Atlas Integration� right?

As I can see from the code you provided, there’s no problem. But I can’t see how you write the logs from your windows service application. So I don’t know if the Source property of the EventLog is setup right.

Based on the code of this document, try to use the below method to log message, and see if you can get the desired result.


 protected override void OnStart(string[] args)
        {
            if (!EventLog.SourceExists("SMS Atlas Integration"))
            {
                // An event log source should not be created and immediately used.
                // There is a latency time to enable the source, it should be created
                // prior to executing the application that uses the source.
                // Execute this sample a second time to use the new source.
                EventLog.CreateEventSource("SMS Atlas Integration", "MyNewLog");
                Console.WriteLine("CreatingEventSource");
                Console.WriteLine("Exiting, execute the application a second time to use the source.");
                // The source is created.  Exit the application to allow it to be registered.
            }

            // Create an EventLog instance and assign its source.
         
            myLog.Source = "SMS Atlas Integration";

            // Write an informational entry to the event log.    
            myLog.WriteEntry("service is started");
            
        }

        protected override void OnStop()
        {
            myLog.WriteEntry("service is stoped");

        }

If I have misunderstood you or the problem can’t be solved, please feel free to let me know.

Best regards,

Bruce Zhou

MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bruce.Zhou  Tuesday, August 18, 2009 10:07 AM

How's your problem now? If the problem is still not solved or any further help from me, please feel free to let me know.

Best regards,

Bruce Zhou

MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bruce.Zhou  Friday, August 21, 2009 4:04 AM

You can use google to search for other answers

Custom Search

More Threads

• Editor for Exes
• Uploading to a web server
• Set language and company
• Making ClickOnce (XBAP) Work With ASP.Net Forms Authentication
• Prerequisites in .NET
• clickonce over ssl with client certificates
• ClickOnce & .NetFX 3.0 Problem
• How to modify app.exe.config.deploy file
• Setting TARGETVDIR to empty at command line?
• C# Setup Project