Solved

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

Posted on 2004-10-26
1,034 Views
Last Modified: 2007-12-19
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
Question by:NewMom2Brandon
    1 Comment
     
    LVL 2

    Accepted Solution

    by:
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This is an explanation of a simple data model to help parse a JSON feed
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now