Have you ever encountered the code works in your local machine but not in server? I think this is one of the common but rare error might be face by developer if using EventLog.Write method.

After some researches, one simple solution can solve the issue, change your application pool default setting! Change the Predefined value to “Local system“. That’s it!

By default the application pool will point to “Network Service” and this service account has no access right to write data to Event viewer. This is not hard to fix but i think will takes time if you are first time on facing this problem, worth to share i think.