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

I'm trying to write to the application event log. This code will be executing on an unattended server so this is the best place to write it. I keep receiving a "Security" error trying to read the security log to see if my logname exists. I'm missing something, but I can't seem to figure out what. I've tried with and without the appLog.Log = "Application";

Here's my code....

Thank you,
Glenn

C#
status = string.Format("{0} - {1}, {2},\n CreateDB (Create 'Server' table) 
                       returned:  {3}, \n{4}",
                        DateTime.Now,
                        System.AppDomain.CurrentDomain.FriendlyName,
                        System.Environment.MachineName,
                        ex1.Message,
                        ex1.StackTrace);

System.Diagnostics.EventLog appLog = new System.Diagnostics.EventLog();
appLog.Source = CommonClass.Product;
appLog.Log = "Application";
appLog.WriteEntry(status);
return (status); 
Posted

1 solution

This is not how it works. It's not quite clear what you are trying to achieve, but probably you are trying to log in the application-specific directory. Here I explain how to achieve that: How to create event log under a folder[^].

—SA
 
Share this answer
 
Comments
gmhanna 21-Dec-13 11:54am    
Hi,

I've tried your method of creating an application log, however i'm still getting the same exception: "The source was not found, but some or all event logs could not be searched. To create the source, you need permission to read all event logs to make sure that the new source name is unique. Inaccessible logs: Security."

The exception is occurring on the CreateEventSource within the Install method:
EventLog.CreateEventSource(ApplicationName, EventLogName);

ApplicationName = "Cert", EventLogName="CommonServices"

I'm running Windows 8.1, not sure if that makes a difference or not.

Thanks,
Glenn

Sergey Alexandrovich Kryukov 21-Dec-13 22:22pm    
I tested my method before posting, it surely work, but I did not try Windows 8 (it would be strange if it is not backward-compatible in this respect). You probably did not reproduce the full cycle of it, say, failed to install the event source due to insufficient permission... What if you try to run installation part as administrator (with elevated permission)?
—SA

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