none
Write to the Windows Event Log from Multiple Sources RRS feed

  • Question

  • Hi,

    I have an application which is responsible for writing errors into the Windows Event Log that are received from multiple different sources. I am trying to write a method that can take the source of an error and the error text then write it into the one Log with differing sources depending on which source is passed in, however I can't seam to get it to work. Just now it appears to only write one of the sources into the custom Log and dumps the rest into the Application log with the description saying it can't find the description. How can I get this method to work as I'm wanting it to?

    void WindowsEventLogger::logError(std::string source, std::string message)
    {       
            System::String^ managedMessage = gcnew String(message.c_str());
            System::String^ managedSource = gcnew String(source.c_str());
            System::String^ managedLogName = gcnew String("TestLog");
     
            if (!EventLog::SourceExists(managedSource))
        {
            EventLog::CreateEventSource(managedSource, managedLogName);
        }
     
            EventLog::WriteEntry(managedSource, managedMessage, EventLogEntryType::Error);  
    }

    To test I've tried calling the method with parameters such as ("Source1", "Message 1 Goes Here") and ("Source2", "Message 2 Goes Here")

    • Edited by Darkness Inc Friday, September 23, 2011 10:54 AM Got rid of garbage added by copy paste
    Friday, September 23, 2011 10:49 AM

Answers

  • you can read KB307024 article from Microsoft!
    Any fool can know. The point is to understand.(Albert Einstein)
    • Marked as answer by Darkness Inc Tuesday, September 27, 2011 9:12 AM
    Sunday, September 25, 2011 8:19 AM
  • It appears I had previously declared the sources I was trying to use to a different log, which persisted across a reboot, so when I did the check to see if the source existed it did so never got re-bound to my log.

     

    To rectify it I created a simple application to check for the sources I wanted to use and if they existed then I deleted them so when I run the application which uses the above code the source would get re-created and bound to the correct log.

    • Marked as answer by Darkness Inc Tuesday, September 27, 2011 9:12 AM
    Tuesday, September 27, 2011 9:11 AM

All replies

  • you can read KB307024 article from Microsoft!
    Any fool can know. The point is to understand.(Albert Einstein)
    • Marked as answer by Darkness Inc Tuesday, September 27, 2011 9:12 AM
    Sunday, September 25, 2011 8:19 AM
  • To me that appears to be what I'm doing, only I'm using the corresponding C++.NET calls
    Tuesday, September 27, 2011 8:51 AM
  • It appears I had previously declared the sources I was trying to use to a different log, which persisted across a reboot, so when I did the check to see if the source existed it did so never got re-bound to my log.

     

    To rectify it I created a simple application to check for the sources I wanted to use and if they existed then I deleted them so when I run the application which uses the above code the source would get re-created and bound to the correct log.

    • Marked as answer by Darkness Inc Tuesday, September 27, 2011 9:12 AM
    Tuesday, September 27, 2011 9:11 AM