EventLog always writes to Application log

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");

}

}

}
 
R

richlm

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.");
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top