EventLog always writes to Application log

  • Thread starter Thread starter Next
  • Start date Start date
N

Next

Hello,

This code writes to the Application log. Isn't it suppose to write to
"NewLog" log?

I'm not getting something here. Can someone help?

Thanks in advance,
Aaron

using System;

using System.Diagnostics;

namespace TestEventLog

{



class Class1

{



[STAThread]

static void Main(string[] args)

{

Class1 c1 = new Class1();

c1.writeLog();

}

private void writeLog ()

{

EventLog el = new EventLog();

el.Source = "NewSource";

el.Log = "NewLog";

el.WriteEntry("hello");

}

}

}
 
You need to associate your new event source with the new event log using
"EventLog.CreateEventSource".
Here's the example from the .NET framework class reference:

using System;
using System.Diagnostics;
using System.Threading;

class MySample{

public static void Main(){

// Create the source, if it does not already exist.
if(!EventLog.SourceExists("MySource", "MyServer")){
EventLog.CreateEventSource("MySource", "MyNewLog", "MyServer");
Console.WriteLine("CreatingEventSource");
}

// Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "MySource";

// Write an informational entry to the event log.
myLog.WriteEntry("Writing to event log.");

Console.WriteLine("Message written to event log.");
}
}
 
Back
Top