If you ever tried to write to the event log, without an event source for that application created you will get an exception saying something along the lines of that you do not have permissions to create the event source.

If an event source does not exist, it is automatically created. The creation of the event source is a privileged operation and requires elevated privileges (a.k.a admin privileges) which of course might not always be possible if running a web application.

The easiest way to create this event source is via a reg file. An example is below (credit goes to my colleague Dominic to provide me the original sample).

Note: you need all the lines below including the “Windows Registry Editor Version 5.00”.

1
2
3
4
5
6
7
8
9
Windows Registry Editor Version 5.00

\[HKEY\_LOCAL\_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\YOUR-APPLICATION-NAME-GOES-HERE\]
"EventMessageFile"=hex(2):43,00,3a,00,5c,00,57,00,49,00,4e,00,44,00,4f,00,57,\\
  00,53,00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,2e,00,\\
  4e,00,45,00,54,00,5c,00,46,00,72,00,61,00,6d,00,65,00,77,00,6f,00,72,00,6b,\\
  00,5c,00,76,00,32,00,2e,00,30,00,2e,00,35,00,30,00,37,00,32,00,37,00,5c,00,\\
  45,00,76,00,65,00,6e,00,74,00,4c,00,6f,00,67,00,4d,00,65,00,73,00,73,00,61,\\
  00,67,00,65,00,73,00,2e,00,64,00,6c,00,6c,00,00,00