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?

Improve company productivity with a Business Account.Sign Up

x
 
pdrauConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.