Gomathipriya
Gomathipriya

Reputation: 945

System.SecurityException error

when i compile the following code it shows the error as system.securityexception error.

using System;    
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace eventlog
{
   class MySample{

public static void Main(){

   if(!EventLog.SourceExists("MySource"))
    {            
        EventLog.CreateEventSource("MySource", "MyNewLog");
        Console.WriteLine("CreatedEventSource");
        Console.WriteLine("Exiting, execute the application a second time to use the source.");
        return;
    }        EventLog myLog = new EventLog();
    myLog.Source = "MySource";
   myLog.WriteEntry("Writing to event log.");

}

} }

how to fix this error

Upvotes: 3

Views: 12600

Answers (3)

JustBeingHelpful
JustBeingHelpful

Reputation: 18980

To be more explicit, right click the application (exe) and choose "Run as Administrator"

Upvotes: 0

Péter
Péter

Reputation: 2181

Read this article: http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx

That is why everybody says not write to eventlog with impersonation. You have to put the user or user group into the local Administrator group whitch is not advised. The service user could have this privilege.

Upvotes: 2

Max
Max

Reputation: 7080

I think you must have Admin privilege for creating new EventLog.

Upvotes: 3

Related Questions