Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can i save event logs using C# ?

How can i save event logs using C# ?

Scheduled Pinned Locked Moved C#
questioncsharp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abhijit Jana
    wrote on last edited by
    #1

    Hi, Is it possible to save event logs using C# ? Any idea ? Thansk in advance !!

    cheers, Abhijit

    E 1 Reply Last reply
    0
    • A Abhijit Jana

      Hi, Is it possible to save event logs using C# ? Any idea ? Thansk in advance !!

      cheers, Abhijit

      E Offline
      E Offline
      ElSpinos
      wrote on last edited by
      #2

      You could use the EventLog object to read the event log entries and then save them to a database or file, like so:

      // Opens the Application event log.
      EventLog eventLog = new EventLog("Application");
      // Iterate through the entries in the opened event log.
      foreach (EventLogEntry entry in eventLog.Entries)
      Console.WriteLine(entry.Message);

      /F - .NET Developer

      modified on Wednesday, July 30, 2008 10:23 AM

      T A 2 Replies Last reply
      0
      • E ElSpinos

        You could use the EventLog object to read the event log entries and then save them to a database or file, like so:

        // Opens the Application event log.
        EventLog eventLog = new EventLog("Application");
        // Iterate through the entries in the opened event log.
        foreach (EventLogEntry entry in eventLog.Entries)
        Console.WriteLine(entry.Message);

        /F - .NET Developer

        modified on Wednesday, July 30, 2008 10:23 AM

        T Offline
        T Offline
        Tuwing Sabado
        wrote on last edited by
        #3

        Use Microsoft Enterprise Library for Event Log, Flat file logging or Error Logging.

        1 Reply Last reply
        0
        • E ElSpinos

          You could use the EventLog object to read the event log entries and then save them to a database or file, like so:

          // Opens the Application event log.
          EventLog eventLog = new EventLog("Application");
          // Iterate through the entries in the opened event log.
          foreach (EventLogEntry entry in eventLog.Entries)
          Console.WriteLine(entry.Message);

          /F - .NET Developer

          modified on Wednesday, July 30, 2008 10:23 AM

          A Offline
          A Offline
          Abhijit Jana
          wrote on last edited by
          #4

          Thanks for your response. but i want to save it ".evt" file.

          cheers, Abhijit

          E 1 Reply Last reply
          0
          • A Abhijit Jana

            Thanks for your response. but i want to save it ".evt" file.

            cheers, Abhijit

            E Offline
            E Offline
            ElSpinos
            wrote on last edited by
            #5

            I don't believe the .NET Framework has native support for this, but you can try the following:

            // Declare this at the class member space
            [DllImport("advapi32.dll")]
            static extern IntPtr OpenEventLog(string lpUNCServerName, string lpSourceName);
            [DllImport("advapi32.dll")]
            static extern bool BackupEventLog(IntPtr hEventLog, string backupFile);

            // Somewhere in your code, call the above two declarations...
            // NOTE: Replace "localhost" with the machine name you need to back up.
            // Replace "Application" with the log you are trying to back up.
            // The saved file is an EVT file.
            BackupEventLog(OpenEventLog("localhost", "Application"), @"C:\TEMP\EVENTLOG.EVT");

            /F - .NET Developer

            A 1 Reply Last reply
            0
            • E ElSpinos

              I don't believe the .NET Framework has native support for this, but you can try the following:

              // Declare this at the class member space
              [DllImport("advapi32.dll")]
              static extern IntPtr OpenEventLog(string lpUNCServerName, string lpSourceName);
              [DllImport("advapi32.dll")]
              static extern bool BackupEventLog(IntPtr hEventLog, string backupFile);

              // Somewhere in your code, call the above two declarations...
              // NOTE: Replace "localhost" with the machine name you need to back up.
              // Replace "Application" with the log you are trying to back up.
              // The saved file is an EVT file.
              BackupEventLog(OpenEventLog("localhost", "Application"), @"C:\TEMP\EVENTLOG.EVT");

              /F - .NET Developer

              A Offline
              A Offline
              Abhijit Jana
              wrote on last edited by
              #6

              Thanks for your reply. I am trying to do it using WMI

              cheers, Abhijit

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups