Link to home
Start Free TrialLog in
Avatar of NewMom2Brandon
NewMom2Brandon

asked on

ASAP ERROR HELP "The type or namespace name 'myLog' could not be found "

I read that you have to declare a source for event log prior to the installer running so I placed the following code in my file called clientinstaller which is in the main project

  public QMonitorInstaller()
        {

          // Create an EventLog instance and assign its source.

          EventLog myLog = new EventLog();
          myLog.Source = "System";

            ServiceProcessInstaller process = new ServiceProcessInstaller();

            process.Account = ServiceAccount.LocalSystem;

            ServiceInstaller serviceAdmin = new ServiceInstaller();

            serviceAdmin.StartType      = ServiceStartMode.Automatic;
            serviceAdmin.ServiceName    = "QMonitor";
            serviceAdmin.DisplayName    = "QMonitor";
           

            Installers.Add( process );
            Installers.Add( serviceAdmin );
        }    
    }    

I also have another file in a connecting Project which contains this line of code

using System;
using System.Xml;
using System.IO;
using System.Collections;
using System.Net;
using Microsoft.Win32;


                myLog.WriteEntry(this.ToString(),
                "dateTimeRunLast = " + dateTimeRunLast.ToString(),
                System.Diagnostics.EventLogEntryType.Error);

I am getting a error error CS0246: The type or namespace name 'myLog' could not be found (are you missing a using directive or an assembly reference?)  How can I fix this error....I try to reference the first project but it says I need a dll...but this is the main project .exe
Avatar of stumpy1
stumpy1

You need to have the following using directive in your code to use the EventLog

using System.Diagnostics;
Avatar of NewMom2Brandon

ASKER

I added it and it still comes up with the same error
Avatar of hes
That link doesn't help much. It is asking for a dll. How do I make a dll to reference the first project which is listed as .exe. How would I reference the Project installer which is where the source for the eventlog is set to be "System"
It would be curtious if he would give us feedback in the thread as to what solved the problem as opposed to just saying 'I found the answer myself'.
If he posts the solution, then we can decide if we have an objection or not.
First off I am not a he!

second here is what I did:

Install.cs file

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;
using System.Diagnostics; ***THIS WAS ALREADY THERE SO THAT DID NOT DO ANYTHING***
 public QMonitorInstaller()
        {

          // Create an EventLog instance and assign its source.

           EventLog myLog = new EventLog("System");
           myLog.Source = "message Agent";

            ServiceProcessInstaller process = new ServiceProcessInstaller();

            process.Account = ServiceAccount.LocalSystem;

            ServiceInstaller serviceAdmin = new ServiceInstaller();

            serviceAdmin.StartType      = ServiceStartMode.Automatic;
            serviceAdmin.ServiceName    = "QMonitor";
            serviceAdmin.DisplayName    = "QMonitor";
           

            Installers.Add( process );
            Installers.Add( serviceAdmin );
        }    
    }    

in my other file

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics; ***EVEN ADDING THIS DID NOT REMOVE THE ERROR INITIALLY until I fixed to code in the installer
using System.ServiceProcess;
using System.Threading;

the normal System.Diagnostics.EventLog.WriteEntry worked.

            System.Diagnostics.EventLog.WriteEntry("Promise Message Agent",
                "Rebuilding successfully completed for disk " + Convert.ToString(cDoubleQuotes) +
                "ST380013AS(Ch2)" + Convert.ToString(cDoubleQuotes) + " in Array " +
                Convert.ToString(cDoubleQuotes) + "PROMISE Array 1" +
                Convert.ToString(cDoubleQuotes) + ".", EventLogEntryType.Error, 533, 0);
Firstly, Please accept my Apologies for the he, if I had taken heed of the username I might have got it right. I try to use (s)he syntax but forget to a lot of the time.
Secondly, I am very glad that you got the problem fixed.
Thirdly, Since you have posted the solution you found this may be a be a useful PAQ for some other soul that runs into a similar problem. Thanks for posting the solution.

My recommendation is that this question should be Paq'd and NewMom2Brandon should have her question points refunded.
I agree
ASKER CERTIFIED SOLUTION
Avatar of ee_ai_construct
ee_ai_construct
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial