Export (0) Print
Expand All

EventLog.LogDisplayName Property

Gets the event log's friendly name.

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

public:
property String^ LogDisplayName {
	String^ get ();
}
/** @property */
public String get_LogDisplayName ()

public function get LogDisplayName () : String

Property Value

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

Exception typeCondition

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.

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
      myLogName = EventLog::LogNameFromSourceName( "MyTestSource", myRemoteMachine );

// Get the EventLog associated if the source exists.
EventLog^ myEventLog1 = gcnew 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 {0}",
   myEventLog1->MachineName );

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

EventLog^ myEventLog2 = gcnew 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 {0}",
   myEventLog2->MachineName );

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.set_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.get_MachineName());
Console.Write("Enter remote computer on which to create log : ");
myRemoteMachine = Console.ReadLine();
EventLog myEventLog2 = new EventLog();
myEventLog2.set_MachineName(myRemoteMachine);
myEventLog2.set_Source("MyTestSource");
myEventLog2.set_Log(myEventLog1.get_LogDisplayName());
myEventLog2.WriteEntry("This is for your information");
Console.WriteLine("An EventLog created on computer " 
    + myEventLog2.get_MachineName());

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft