Export (0) Print
Expand All

EventLog.LogNameFromSourceName Method

Gets the name of the log to which the specified source is registered.

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

public static string LogNameFromSourceName (
	string source,
	string machineName
)
public static String LogNameFromSourceName (
	String source, 
	String machineName
)
public static function LogNameFromSourceName (
	source : String, 
	machineName : String
) : String
Not applicable.

Parameters

source

The name of the event source.

machineName

The name of the computer on which to look, or "." for the local computer.

Return Value

The name of the log associated with the specified source in the registry.

The event source indicates what logs the event. It is often the name of the application, or the name of a subcomponent of the application, if the application is large. Applications and services should write to the Application log or a custom log. Device drivers should write to the System log.

When you create a new source, which can only write to one log at a time, the system registers your application with the event log as a valid source of entries. The Source property can be any string, but the name cannot be used by other sources on the computer. An attempt to create a duplicated Source value throws an exception. However, a single event log can have many different sources writing to it.

The following example deletes a source from the local computer. The example determines the log from its source, and then deletes the log.

NoteNote:

More than one source might write to an event log. Before deleting a custom log, make sure there are no other sources writing to that log.

using System;
using System.Diagnostics;
using System.Threading;
              
class MySample{

    public static void Main(){

         string logName;
       
        if(EventLog.SourceExists("MyOldSource")){
        // Find the log associated with this source.    
            logName = EventLog.LogNameFromSourceName("MyOldSource", ".");

        // Delete the source and the log.
            EventLog.DeleteEventSource("MyOldSource");
            EventLog.Delete(logName);
            
            Console.WriteLine(logName + " deleted.");    
        }                                                                        
    } 
}
   

import System.*;
import System.Diagnostics.*;
import System.Threading.*;

class MySample
{
    public static void main(String[] args)
    {
        String logName;
        if (EventLog.SourceExists("MyOldSource")) {
            // Find the log associated with this source.    
            logName = EventLog.LogNameFromSourceName("MyOldSource", ".");

            // Delete the source and the log.
            EventLog.DeleteEventSource("MyOldSource");
            EventLog.Delete(logName);
            Console.WriteLine(logName + " deleted.");
        }
    } //main
} //MySample

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft