tags:

views:

60

answers:

3

Hi,

I'm trying to read event logs for my application EventLoggingApp. The problem is reading logs for my single source (EventLoggingApp).

This code read logs for every source. What is the problem? Any advice?

static void ReadEvenLog()
{
    string eventLogName = "Application";

    string sourceName = "EventLoggingApp";

    string machineName ="Tom";

    EventLog eventLog;

    eventLog = new EventLog();

    eventLog.Log = eventLogName;

    eventLog.Source = sourceName;

    eventLog.MachineName = machineName;

    foreach (EventLogEntry log in eventLog.Entries)
    {
        Console.WriteLine("{0}\n",log.Source);
    }
}
A: 

If you connect to localhost set MachineName to "." Check if user has right to read from eventlog

Aik
Since he gets ALL logs from his machine, there are no security problems.
atamanroman
A: 

Check out this article on MSDN. You can't read event log entries by source. Only log name matters. Instead you can create separate event log for you application or filter entries by verifying Source property of each entry in foreach loop.

Btw, sorry for my english. I'm from Russia. =)

Vyacheslav
Thx, I am from Slovakia, your eng is much more better than my :)
Tom159
A: 

MSDN (1)(2) says that Source is for writing event logs only.

It is not necessary to specify a Source when only reading from a log. You can specify only the Log name and MachineName (server computer name) properties for the EventLog instance. In either case, the Entries member is automatically populated with the event log's list of entries. You can select the appropriate index for an item in this list to read individual entries. (1)

atamanroman