Try to log into EventLog

Topics: Logging Application Block
Dec 3, 2009 at 9:12 AM

Hi,

The last few evenings I was creating a new windows application, using the Logging block. But what I did: the application wasn't logging in the eventlog.

Finally I found the problem: using Windows 7 (64bt) with UAC the application (from VS2008 while debugging) can't create the application registry-key for the event log. When I disable UAC it will create the key and everything works. When I turn UAC on again, everything works fine, because the key already exist.

I have checked the source-code of the Logging block and there is an exception that raised, but that exception cannot handled by my own application (it is handled in the block itself).

When I want to deploy the application, the user can changed the source (that is used for the eventlog) from the app.config. But if the user haven't got the admin rights, logging doesn't work anymore.

At this moment I have changed my source code:

If (! EventLog.SourceExists("appname"))

{

Dim id As WindowsIdentity = WindowsIdentity.GetCurrent
Dim p As WindowsPrincipal = New WindowsPrincipal(id)
If (p.IsInRole(WindowsBuiltInRole.Administrator))
{

EventLog.CreateEventSource("appname");

}

else

{

throw Exception("Can't create Eventlog and user haven't got Admin rights")

}

}

Logger.Write(.....);

 

Is it possible to handle this in the next release of EntLib?? Or maybe a static method that is trying to create the eventlogs that are specified by the application??

Is there a solution for debugging this in VS2008 (with UAC enabled), when the EventLog doesn't exist??

 

Regards,

Donovan

Dec 3, 2009 at 9:17 AM

In my example there are 2 languages: C# and VB.NET (sample from http://www.eggheadcafe.com/software/aspnet/33083374/exception-handling-block.aspx).

It must be

WindowsIdentity id = WindowsIdentity.GetCurrent;

WindowsPrincipal p = new WindowsPrincipal(id);

Regards,

Donovan

Dec 3, 2009 at 10:10 AM

Hi,

Well confirm this with the ent lib team.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com