Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dears,

I 've a problem with creating event log on event viewer.
The issue is as following:
I am using this code to create event log in event viewer.
C#
private static void WriteEventLogEntry(string message)
        {
            try
            {
                try { if (!EventLog.SourceExists("COO")) { EventLog.CreateEventSource("COO", "COOLog"); } }
                catch (Exception) { }
                EventLog Log = new EventLog();
                Log.Source = "COOLog";
                Log.WriteEntry(message, EventLogEntryType.Error, 0);
            }
            catch (Exception ex) { }
        }


Actually, Everything is done very well on my PC.
but after publishing to server, i faced a permission issue that i must be administrator.

I thought i could create this file manually by using command prompt or something else but i couldn't do that.

So, now can any one help me how to solve this permission issue by code or add event log to (Applications and services logs) Folder manually by command prompt?

Thanks in advance.

What I have tried:

I have tried this line to add it by command prompt, but the log is created in Application logs not in (Applications and services logs) Folder.

eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO COO /D "COOLog"
Posted
Updated 5-May-16 3:46am

1 solution

Creating an event source requires administrator permissions. This is something that is normally done at install time, by your installer, not at application run time.


You can only create an event in one log at a time. If you want an event to show up in multiple logs you have to create separate events for each log.
 
Share this answer
 
Comments
_ProgProg_ 5-May-16 9:48am    
isn't there is any way to create the event log manually using command prompt?
Dave Kreskowiak 5-May-16 10:06am    
The "eventcreate" command does not create an event source. It's used to create event log entries, which still requires admin permissions.

There is no command line tool to create an event source.

Do you know the differences between an event log, an event source, and an event? I seriously recommend looking those terms up.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900