Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Custom Event Log


Message #1 by "Stefano Rigat" <srigat@e...> on Tue, 7 Jan 2003 12:10:28 +0100
Hi Imar (and Andrew),

I got your point. In fact, the block of code I'm running is controlled by
another application, which ALWAYS provides the same Name and Source for the
custom Log I created. It is not intended as a function to be used by end
users.

Thanks for the useful link (I knew the Data Access Application Block, I
didn't know this one - very useful!).

Anyway, I solved the problem : it was not a matter of permissions, just
wrong coding. If anybody is interested, this code is working :

		public void LogException(string pLogName, string pSource, Exception ex)
		{
			EventLog el = new EventLog(pLogName, ".", pSource);

			if (!EventLog.SourceExists(pSource))
			{
			 	EventLog.CreateEventSource(pSource, pLogName, ".");
			}

			string strMessage = "Exception Source : " + ex.Source + "; Message : " +
ex.Message;
			el.WriteEntry(strMessage, EventLogEntryType.Information);

		}

where "." is for the Local Machine.

Stefano



-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: martedi 7 gennaio 2003 17.04
To: ASPX_Professional
Subject: [aspx_professional] RE: Custom Event Log


Hi Stefano,

I still think Andrew has a point. Although the docs specify you could do
this, there are major security issues involved.
If you take a look at the Microsoft Exception Management Application Blocks
(at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/
emab-rm.asp

)

you'll see that from the beta version to the final release, they removed
the option to create the logs at run time, but instead create them at
install time now. Their main reason for doing this were security issues.
So, although I am sure you can avoid the problem by giving additional
rights to the ASPNET account, IMO it's better to create the logs at install
time, and then depend on those at run time.

Cheers,

Imar


At 01:34 PM 1/7/2003 +0100, you wrote:
>Andrew, thanks for your advice, but maybe I did not explain my problem
>correctly.
>
>Here is an abstract of MSDN help from Microsoft (MS english is far better
>than mine...) :
>
>(ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbtskcreatingremovingcustomlogseven
t
>sources.htm)
>
>You can use the EventLog class to create a custom event log on a local or
>remote computer. You might create a custom log if you wanted to organize
>your entries in a more granular way than is allowed when your components
>write entries to the default Application log. For example, suppose you have
>a component called OrderEntry that writes entry information to an event
log.
>You are interested in backing up and saving these entries for a longer
>period of time than some other entries in the Application log. Rather than
>registering your component to write to the Application log, you can create
a
>custom log called OrdersLog and register your component to write entries to
>that log instead. That way, all of your order information is stored in one
>place and will not be affected if the entries in the Application log are
>cleared.
>
>The following example shows how to create a custom log called MyNewLog on
>the local machine. This code assumes that an Imports or Using statement
>exists for the System.Diagnostics namespace:
>
>EventLog.CreateEventSource("MyApp1", "MyNewLog");
>
>Now, the question is : why the system throws an Exception stating that
>"Requested registry access is not allowed." ?  Permissions ?
>
>Thank you.
>
>Stefano





  Return to Index