Export (0) Print
Expand All

EventLog.LogDisplayName Property

Gets the event log's friendly name.

[Visual Basic]
Public ReadOnly Property LogDisplayName As String
[C#]
public string LogDisplayName {get;}
[C++]
public: __property String* get_LogDisplayName();
[JScript]
public function get LogDisplayName() : String;

Property Value

A name that represents the event log in the system's event viewer.

Exceptions

Exception Type Condition
Exception The log does not exist on the computer specified by the MachineName property.
SystemException The application could not open the registry key associated with this event log.

Example

[Visual Basic] 
Dim myRemoteMachine As String
Dim myLogName as string = "MyLog"
Console.Write("Enter computer on which to create log : ")
myRemoteMachine = Console.ReadLine()

' Check if the source exists.
if not EventLog.SourceExists("MyTestSource") then
   'Create source.
   EventLog.CreateEventSource("MyTestSource", myLogName,myRemoteMachine)
   Console.WriteLine("Creating EventSource")
else
   'Get the EventLog associated if the source exists.
   myLogName = EventLog.LogNameFromSourceName("MyTestSource",myRemoteMachine)
end if

Dim myEventLog1 As New EventLog(myLogName, myRemoteMachine)
myEventLog1.Source = "MyTestSource"
' Write an entry into log.
myEventLog1.WriteEntry("This is for your information", _
                     EventLogEntryType.SuccessAudit, 100)
Console.WriteLine("An EventLog created on computer " + myEventLog1.MachineName)
Console.Write("Enter remote computer on which to create log : ")
myRemoteMachine = Console.ReadLine()

Dim myEventLog2 As New EventLog()
myEventLog2.MachineName = myRemoteMachine
myEventLog2.Source = "MyTestSource"
myEventLog2.Log = myEventLog1.LogDisplayName
myEventLog2.WriteEntry("This is for your information")
Console.WriteLine("An EventLog created on computer " + myEventLog2.MachineName)

[C#] 
string myRemoteMachine;
string myLogName = "MyLog";

Console.Write( "Enter computer on which to create log : " );
myRemoteMachine = Console.ReadLine();

// Check if the source exists.
if(!EventLog.SourceExists("MyTestSource"))
{
   //Create source.
   EventLog.CreateEventSource("MyTestSource", myLogName,myRemoteMachine);
   Console.WriteLine("Creating EventSource");
}
else
   // Get the EventLog associated if the source exists.
   myLogName = EventLog.LogNameFromSourceName("MyTestSource",myRemoteMachine);

EventLog myEventLog1 = new EventLog(myLogName,myRemoteMachine);
myEventLog1.Source = "MyTestSource";
// Write an entry into log.
myEventLog1.WriteEntry("This is for your information",
                               EventLogEntryType.SuccessAudit,100);
Console.WriteLine("An EventLog created on computer "+ 
                               myEventLog1.MachineName);

Console.Write( "Enter remote computer on which to create log : " );
myRemoteMachine = Console.ReadLine();

EventLog myEventLog2 = new EventLog();
myEventLog2.MachineName = myRemoteMachine;
myEventLog2.Source = "MyTestSource";
myEventLog2.Log = myEventLog1.LogDisplayName;
myEventLog2.WriteEntry("This is for your information");
Console.WriteLine("An EventLog created on computer "+ 
                                   myEventLog2.MachineName);

[C++] 
String* myRemoteMachine;
String* myLogName = S"MyLog";

Console::Write(S"Enter computer on which to create log : ");
myRemoteMachine = Console::ReadLine();

// Check if the source exists.
if (!EventLog::SourceExists(S"MyTestSource")) {
    //Create source.
    EventLog::CreateEventSource(S"MyTestSource", myLogName,myRemoteMachine);
    Console::WriteLine(S"Creating EventSource");
} else
    // Get the EventLog associated if the source exists.
    myLogName = EventLog::LogNameFromSourceName(S"MyTestSource",myRemoteMachine);

EventLog* myEventLog1 = new EventLog(myLogName,myRemoteMachine);
myEventLog1->Source = S"MyTestSource";
// Write an entry into log.
myEventLog1->WriteEntry(S"This is for your information",
    EventLogEntryType::SuccessAudit,100);
Console::WriteLine(S"An EventLog created on computer {0}", myEventLog1->MachineName);

Console::Write(S"Enter remote computer on which to create log : ");
myRemoteMachine = Console::ReadLine();

EventLog* myEventLog2 = new EventLog();
myEventLog2->MachineName = myRemoteMachine;
myEventLog2->Source = S"MyTestSource";
myEventLog2->Log = myEventLog1->LogDisplayName;
myEventLog2->WriteEntry(S"This is for your information");
Console::WriteLine(S"An EventLog created on computer {0}", myEventLog2->MachineName);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

EventLog Class | EventLog Members | System.Diagnostics Namespace

Show:
© 2015 Microsoft