0

Simple Windows console app:

using System.Diagnostics;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            EventLog.WriteEntry("Application", "HELLO!", EventLogEntryType.Error, 22);
        }
    }
}

When I run this (as a local admin) on Server 2012, it works - except the message is not displayed when I view this event in Server Manager. Why is the message ("HELLO!") not showing up?

EDIT: Screenshot of Server Manager: enter image description here

Conrad
  • 2,197
  • 28
  • 53
  • So when you say "it works" you mean, "it does not produce a error"? or is it the event showing up but the text of the event is blank? – Scott Chamberlain Dec 13 '13 at 21:58
  • @ScottChamberlain the latter. – Conrad Dec 13 '13 at 21:59
  • Then [edit your question](http://stackoverflow.com/posts/20576706/edit) and include the relevant details. (a copy of what does show up would be helpful, even a screenshot) – Scott Chamberlain Dec 13 '13 at 22:03
  • @ScottChamberlain screenshot added. – Conrad Dec 13 '13 at 22:19
  • You code works ok. I think this a localised issue for Server Manager. You see the standard eventlog with the 'HELLO!' message write? – Spock Dec 14 '13 at 00:02
  • @Spock: "You see the standard eventlog with the 'HELLO!' message write?" I don't understand what you're asking here. – Conrad Dec 14 '13 at 00:14
  • Yes I see the standard even log entry. Just confirmed with you and that was the question. All I'm saying is your issue is related to the way you view the messages. For example "localised issue for Server Manager." – Spock Dec 14 '13 at 00:31
  • @Spock That seems odd that it would be a localization issue, as I am using the default US-English settings for the OS. Can you point me to where I change how I view the messages? – Conrad Dec 14 '13 at 01:00
  • Sorry you misunderstood my comment. What I meant by "localised issue" means, an isolated issue within the Server Manager itself, could be permission related. Because your code works fine :) – Spock Dec 14 '13 at 01:08

1 Answers1

3

Figured out the problem - the first arg of EventLog is not which log to write the info to (thought I saw that was the case in some doc), but the name of source of the message which should be shown in the log. For whatever reason, it fails when that source name is "Application". Changing it to something more relevant makes it work.

Conrad
  • 2,197
  • 28
  • 53