Export (0) Print
Expand All

EventLog.LogDisplayName Property

Gets the event log's friendly name.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)

'Declaration
<BrowsableAttribute(False)> _
Public ReadOnly Property LogDisplayName As String

Property Value

Type: System.String
A name that represents the event log in the system's event viewer.

ExceptionCondition
InvalidOperationException

The specified Log does not exist in the registry for this computer.

NoteNote

In Windows Vista and later, users do not have permission to access the security log. If you are running Windows Vista or later as a user, you will get a SecurityException when you attempt to access the display name for an event in the security log.

In Windows Vista and later, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. To execute the code that accesses the security log, you must first elevate your privileges from standard user to administrator. You can do this when you start an application by right-clicking the application icon and indicating that you want to run as an administrator.

The following example enumerates the event logs defined on the local computer and displays the LogDisplayName for each event log.

Shared Sub DisplayEventLogProperties()

   ' Iterate through the current set of event log files, 
   ' displaying the property settings for each file. 
   Dim eventLogs As EventLog() = EventLog.GetEventLogs()

   Dim e As EventLog
   For Each e In  eventLogs
      Dim sizeKB As Int64 = 0

      Console.WriteLine()
      Console.WriteLine("{0}:", e.LogDisplayName)
      Console.WriteLine("  Log name = " + ControlChars.Tab _
                          + ControlChars.Tab + " {0}", e.Log)

      Console.WriteLine("  Number of event log entries = {0}", e.Entries.Count.ToString())

      ' Determine if there is an event log file for this event log. 
      Dim regEventLog As RegistryKey
      regEventLog = Registry.LocalMachine.OpenSubKey( _
             ("System\CurrentControlSet\Services\EventLog\" + e.Log))

      If Not (regEventLog Is Nothing) Then 

         Dim temp As Object = regEventLog.GetValue("File")
         If Not (temp Is Nothing) Then

            Console.WriteLine("  Log file path = " + ControlChars.Tab _
                                  + " {0}", temp.ToString())
            Dim file As New FileInfo(temp.ToString())

            ' Get the current size of the event log file. 
            If file.Exists Then
               sizeKB = file.Length / 1024
               If file.Length Mod 1024 <> 0 Then
                  sizeKB += 1
               End If
               Console.WriteLine("  Current size = " + ControlChars.Tab _
                          + " {0} kilobytes", sizeKB.ToString())
            End If 
         Else
            Console.WriteLine("  Log file path = " + ControlChars.Tab _
                             + " <not set>")
         End If 
      End If 

      ' Display the maximum size and overflow settings.
      sizeKB = e.MaximumKilobytes
      Console.WriteLine("  Maximum size = " + ControlChars.Tab _
                         + " {0} kilobytes", sizeKB.ToString())
      Console.WriteLine("  Overflow setting = " + ControlChars.Tab _
                         + " {0}", e.OverflowAction.ToString())

      Select Case e.OverflowAction
         Case OverflowAction.OverwriteOlder
            Console.WriteLine(ControlChars.Tab + _
                 " Entries are retained a minimum of {0} days.", _
                 e.MinimumRetentionDays)
         Case OverflowAction.DoNotOverwrite
            Console.WriteLine(ControlChars.Tab + _
                 " Older entries are not overwritten.")
         Case OverflowAction.OverwriteAsNeeded
            Console.WriteLine(ControlChars.Tab + _
                 " If number of entries equals max size limit, a new event log entry overwrites the oldest entry.")
         Case Else 
      End Select 

   Next e

End Sub

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Show:
© 2015 Microsoft