Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1090
  • Last Modified:

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 #");
         }

      }
0
NewMom2Brandon
Asked:
NewMom2Brandon
1 Solution
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now