URGENT HELP NEEDED.....Errors in 'System.Diagnostics.EventLog.WriteEntry & 'System.Diagnostics.EventLogEntryType'

error CS1502: The best overloaded method match for 'System.Diagnostics.EventLog.WriteEntry(string, string, System.Diagnostics.EventLogEntryType)' has some invalid arguments
error CS1503: Argument '3': cannot convert from 'string' to 'System.Diagnostics.EventLogEntryType'
error CS1502: The best overloaded method match for 'System.Diagnostics.EventLog.WriteEntry(string, string, System.Diagnostics.EventLogEntryType)' has some invalid arguments
error CS1503: Argument '3': cannot convert from 'string' to 'System.Diagnostics.EventLogEntryType'

What can I do to fix the error with the sData. I need to have the original message string be posted into the errorlog.


     private void ReceiveData(Byte [] byteBuffer, int size)
      {
         string sData = Encoding.ASCII.GetString(byteBuffer,0, size);
         
        // Initializes the variables to pass to the MessageBox.Show method.
         string errMsg = "Disk Failure".PadLeft(300, ' ').PadRight(300, ' ');

         try
         {
            if((sData.ToLower().IndexOf("disk") > -1) &&
               (sData.ToLower().IndexOf("failed") > -1))
            {
               System.Diagnostics.EventLog.WriteEntry(this.ToString(),
               "Failure Msg received", sData);   ****ERROR IS HERE WITH sDATA****

               // Displays the MessageBox.

                  MessageBox.Show(errMsg, "WARNING!!", MessageBoxButtons.OK,
                  MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                  MessageBoxOptions.ServiceNotification);

            }

            else if((sData.ToLower().IndexOf("disk") > -1) &&
               (sData.ToLower().IndexOf("rebuilding") > -1) &&
               (sData.ToLower().IndexOf("successfully") > -1))
            {
               // post the message in the error log
               System.Diagnostics.EventLog.WriteEntry(this.ToString(),
               "Rebuild Msg Received", sData);  ****ERROR IS HERE WITH sDATA****
            }

            else
               System.Diagnostics.EventLog.WriteEntry(this.ToString(),
                  "EventListener, Can't process data" + "::Stopped");
         }

         catch(InvalidCastException e)
         {
            System.Diagnostics.EventLog.WriteEntry(this.ToString(),
               "InvalidCast Error #");
         }

      }
LVL 2
NewMom2BrandonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pdrauCommented:
You are trying to use EventLog.WriteEntry Method (String, String, EventLogEntryType)

The EventLogEntry Type should not be a string and therefore is causing the error.

Here's part an example found in EventLogEntryType Enumeration entry in Visual Studio.NET help.

switch( myIntLog )
{
   case 1:
      // Write an 'Error' entry in specified log of event log.
      myEventLog.WriteEntry( myMessage, EventLogEntryType.Error, myID );
      break;
   case 2:
      // Write a 'Warning' entry in specified log of event log.
      myEventLog.WriteEntry( myMessage, EventLogEntryType.Warning, myID );
      break;
   case 3:
      // Write an 'Information' entry in specified log of event log.
      myEventLog.WriteEntry( myMessage, EventLogEntryType.Information, myID );
      break;
   case 4:
      // Write a 'FailureAudit' entry in specified log of event log.
      myEventLog.WriteEntry( myMessage, EventLogEntryType.FailureAudit, myID );
      break;
   case 5:
      // Write a 'SuccessAudit' entry in specified log of event log.
      myEventLog.WriteEntry( myMessage, EventLogEntryType.SuccessAudit, myID );
      break;
   default:
      Console.WriteLine("Error: Failed to create an event in event log.");
     break;
}


Your code:

 // post the message in the error log
               System.Diagnostics.EventLog.WriteEntry(this.ToString(),
               "Rebuild Msg Received", sData);  ****ERROR IS HERE WITH sDATA****

The sData value needs to be EventLogEntryType.OneOfTheValidTypes

The valid type members:

Member name Description
Error                An error event. This indicates a significant problem the user should know about; usually a loss of functionality or data.
FailureAudit      A failure audit event. This indicates a security event that occurs when an audited access attempt fails; for example, a failed attempt to open a file.
Information       An information event. This indicates a significant, successful operation.
SuccessAudit     A success audit event. This indicates a security event that occurs when an audited access attempt is successful; for example, logging on successfully.
Warning            A warning event. This indicates a problem that is not immediately significant, but that may signify conditions that could cause future problems.


Hope this helps resolve your question.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.