Correct method of installing an ASP.NET Event Log logging source

Topics: Logging Application Block
Jun 13, 2008 at 1:39 PM
Edited Jun 13, 2008 at 1:41 PM

Hello

I am trying to use the Logging Application Block to log unhandled exceptions in my ASP.NET web site. And using the LAB, I am trying to write to the Windows event log.

It works on my development machine all by itself, obviously because I am an administrator.

I then added a custom install action to iterate and install the event logs necesarry as per ploeh's post here: http://blogs.msdn.com/ploeh/archive/2007/09/20/InstallingEventSourcesForTheLoggingApplicationBlock.aspx

When I deploy to my server, the install succeeds, and my event log is visible, but when I attempt to write to it I get the following error:

 The description for Event ID ( 1 ) in Source ( Enterprise Library Logging ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Message: A test error

 And then it gives my entire log text

My question is twofold:
1.) Am I trying to install the logs incorrectly?
2.) If not, what permissions should I be checking, or how do I try to work out why the LAB cannot resolve the message ID?

I have tried editing my registry permissions and entries, but with no success.

Please help :-D

Thanks,
Joon

Jun 13, 2008 at 2:42 PM


Joonr wrote:

When I deploy to my server, the install succeeds, and my event log is visible, but when I attempt to write to it I get the following error:

 The description for Event ID ( 1 ) in Source ( Enterprise Library Logging ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Message: A test error

 And then it gives my entire log text

 

Some additional info:

When I try to install to my own customer event log, I get the error mentioned above. If I change my configuration and install my new source in the Application log, everything works fine.

What could be different between the Application log and a customer log created with an EventLog install action?

Thanks in advance for helping,
Joon
Jun 13, 2008 at 3:41 PM

Hi,

Event log sources installed using installutil will have by default a standard message DLL (C:\Windows\Microsoft.NET\Framework64\v2.0.50727\EventLogMessages.dll in my case.) This DLL has entries for all possible message IDs - 65k of them since the ID is a 16-bits int - with the same message template "%1". This is intended to be used with the EventLog.WriteEntry set of messages, which supply string that is displayed as the event's complete message because this string is used as the only parameter %1 in the call to the Win32 EventLog API; this WriteEntry API is used by the EventLogTraceListener which EntLib uses.

You mentioned the registry. Can you verify there's an entry like this in the registry after installing?

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\[log name]\[source name]
"EventMessageFile"=[path to the .net framework]\v2.0.50727\EventLogMessages.dll


I would think after you've called the EventLog API the permissions for the user running the app should not matter, but can you provide additional information about the exception you get?

Fernando

 


Joonr wrote:


Joonr wrote:

When I deploy to my server, the install succeeds, and my event log is visible, but when I attempt to write to it I get the following error:

 The description for Event ID ( 1 ) in Source ( Enterprise Library Logging ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Message: A test error

 And then it gives my entire log text

 

Some additional info:

When I try to install to my own customer event log, I get the error mentioned above. If I change my configuration and install my new source in the Application log, everything works fine.

What could be different between the Application log and a customer log created with an EventLog install action?

Thanks in advance for helping,
Joon


Jul 18, 2008 at 11:49 AM
Hi,

I used administrator account to run 

per ploeh's post : http://blogs.msdn.com/ploeh/archive/2007/09/20/InstallingEventSourcesForTheLoggingApplicationBlock.aspx in Windows Server 2003

and I was able to create Enterprise Library Source in Application Log (verified in registry editor under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\[log name]\[source name]) .  However, web app running under Application pool with minimal user rights still does not log to the Application Log. 

I tried to store to a custom log 'MyLog' and I cannot open that log file in Event Viewer to check if the errors were logged.  Whenever I try to open custom logfile it says the logfile is currently being used by another process.

Is there a way to use Enterprise Library EHAB to write to the application or to a custom log which can be opened in Event Viewer?


Thanks in advance for helping,

Robert
Jul 18, 2008 at 3:15 PM
Hi,

You certainly can write to a different log; in fact the unit tests write to the custom "EntLib Tests" log.

You mention you have a web application and app pool with minimal user rights. What do you mean by that? Is the identity for the app pool that has low privileges?
If you're runing in medium-trust, by default you cannot write to the event log. There's information about what to do in http://msdn.microsoft.com/en-us/library/ms998341.aspx#paght000020_oledbpermission.

Hope this helps,
Fernando




robertu wrote:
Hi,

I used administrator account to run 

per ploeh's post : http://blogs.msdn.com/ploeh/archive/2007/09/20/InstallingEventSourcesForTheLoggingApplicationBlock.aspx in Windows Server 2003

and I was able to create Enterprise Library Source in Application Log (verified in registry editor under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\[log name]\[source name]) .  However, web app running under Application pool with minimal user rights still does not log to the Application Log. 

I tried to store to a custom log 'MyLog' and I cannot open that log file in Event Viewer to check if the errors were logged.  Whenever I try to open custom logfile it says the logfile is currently being used by another process.

Is there a way to use Enterprise Library EHAB to write to the application or to a custom log which can be opened in Event Viewer?


Thanks in advance for helping,

Robert



Jul 20, 2008 at 3:35 AM
Hi Fernando,

Thanks for the reply.

I'm not running on medium trust.  However, I just added a TraceListener on Logging Errors & Warnings Special Category and it started logging to the custom/Application Log.  My other question is how do I open a custom log in Event Viewer?  I tried using Open a Saved Log and it gives me an error that the logfile is currently in used by another process.

Also, I was using the Unity Container to initialize the ExceptionManager instance and it give me the error:

[NullReferenceException: Object reference not set to an instance of an object.]
   Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter..ctor(String template, IDictionary`2 extraTokenHandlers) +118
   BuildUp_Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter(IBuilderContext ) +243
   Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +12
   Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +182
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +91

[BuildFailedException: The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Text Formatter]) failed: Object reference not set to an instance of an object. (Strategy type Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy, index 2)]
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +264
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity.ReferenceResolverPolicy.Microsoft.Practices.ObjectBuilder2.IDependencyResolverPolicy.Resolve(IBuilderContext context) +66
   BuildUp_Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener(IBuilderContext ) +459

.
.
.
.

[InvalidOperationException: The parameter exceptionManager could not be resolved when attempting to call constructor MembershipExtensionDB(Microsoft.Practices.EnterpriseLibrary.Data.Database db, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManager exceptionManager).]
   Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForResolutionFailed(Exception inner, String parameterName, String constructorSignature, IBuilderContext context) +167
   BuildUp_MembershipExtensionDB(IBuilderContext ) +399
   Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +12
   Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +182
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +91

[BuildFailedException: The current build operation (build key Build Key[MembershipExtensionDB, null]) failed: The parameter exceptionManager could not be resolved when attempting to call constructor MembershipExtensionDB(Microsoft.Practices.EnterpriseLibrary.Data.Database db, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManager exceptionManager). (Strategy type Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy, index 2)]
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +264
   Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing) +93
   Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name) +144






on initial load/run in the IIS 6.0.  I do not get that error on succeeding load/rerun unless I change the website again.


Thanks for the help,

Robert
Jul 21, 2008 at 1:21 PM

You're probably hitting the issue described here http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=29005. There's a workaround, but it requires recompiling EntLib.

About how to open you custom log, it should be available in the event viewer. What's your OS?

Fernando


robertu wrote:
Hi Fernando,

Thanks for the reply.

I'm not running on medium trust.  However, I just added a TraceListener on Logging Errors & Warnings Special Category and it started logging to the custom/Application Log.  My other question is how do I open a custom log in Event Viewer?  I tried using Open a Saved Log and it gives me an error that the logfile is currently in used by another process.

Also, I was using the Unity Container to initialize the ExceptionManager instance and it give me the error:

[NullReferenceException: Object reference not set to an instance of an object.]
   Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter..ctor(String template, IDictionary`2 extraTokenHandlers) +118
   BuildUp_Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter(IBuilderContext ) +243
   Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +12
   Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +182
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +91

[BuildFailedException: The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Text Formatter]) failed: Object reference not set to an instance of an object. (Strategy type Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy, index 2)]
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +264
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity.ReferenceResolverPolicy.Microsoft.Practices.ObjectBuilder2.IDependencyResolverPolicy.Resolve(IBuilderContext context) +66
   BuildUp_Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener(IBuilderContext ) +459

.
.
.
.

[InvalidOperationException: The parameter exceptionManager could not be resolved when attempting to call constructor MembershipExtensionDB(Microsoft.Practices.EnterpriseLibrary.Data.Database db, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManager exceptionManager).]
   Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForResolutionFailed(Exception inner, String parameterName, String constructorSignature, IBuilderContext context) +167
   BuildUp_MembershipExtensionDB(IBuilderContext ) +399
   Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +12
   Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +182
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +91

[BuildFailedException: The current build operation (build key Build Key[MembershipExtensionDB, null]) failed: The parameter exceptionManager could not be resolved when attempting to call constructor MembershipExtensionDB(Microsoft.Practices.EnterpriseLibrary.Data.Database db, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManager exceptionManager). (Strategy type Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy, index 2)]
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +264
   Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing) +93
   Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name) +144






on initial load/run in the IIS 6.0.  I do not get that error on succeeding load/rerun unless I change the website again.


Thanks for the help,

Robert


Sep 1, 2010 at 10:17 PM
Edited Sep 2, 2010 at 2:54 PM

I followed several rabbit trails on this one, and here is what I discovered.

I was getting the same type of message in my Event Log.

 

The description for Event ID ( 2001 ) in Source ( Enterprise Library Logging ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details.

 

I have a Windows Service that is using the Enterprise Library Logging Application Block.

 

So I followed this previously mentioned blog entry:
http://blogs.msdn.com/b/ploeh/archive/2007/09/20/installingeventsourcesfortheloggingapplicationblock.aspx

I also following this KB:

http://support.microsoft.com/kb/329291/en-us


I originally used "First Approach" to hand edit the registry.

What I ended up doing was.

 

1.  I coded up the "Second Approach" from the MS KB.

2.  I added in the installingeventsourcesfortheloggingapplicationblock.aspx code ... into the "Second Approach".

Code looked something like this:

 

 [RunInstaller(true)]
    public class EventLogInstallerHelper : Installer
    {
        private EventLogInstaller _eventLogInstaller1;


        private static readonly string EVENT_VIEW_TYPE_APPLICATION = "Application";

        public EventLogInstallerHelper()
        {
            //Create Instance of EventLogInstaller
            _eventLogInstaller1 = new EventLogInstaller();

            // Set the Source of Event Log, to be created.
            _eventLogInstaller1.Source = "Enterprise Library Logging";

            // Set the Log that source is created in
            _eventLogInstaller1.Log = EVENT_VIEW_TYPE_APPLICATION;

            // Add myEventLogInstaller to the Installers Collection.
            Installers.Add(_eventLogInstaller1);


            this.Installers.Add(new LoggingApplicationBlockEventLogInstaller());

        }
    }
}

3.  (IMPORTANT: (If you were like me and followed the "First Approach" from the MS KB) I had to undo what I did in the "First Approach" MS KB.

I did this by calling the

InstallUtil /u EventLogSourceInstaller.dll

You must undo the "First Approach"

4.  I ran the InstallUtil EventLogSourceInstaller.dll

 

At the end of it, I had this key defined (which is the same as "First Approach" as above.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\Enterprise Library Logging

 

However, it had an "Expandable String Value" defined under it (which did not exist using the "First Approach" in the MS KB article)

The name of the value was "EventMessageFile"

and its value (REG_EXPAND_SZ) was "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.dll" (no quotes)

( obviously, the path has to match to your copy of EventLogMessages.dll )

 

So obviously, the "coded up solution" using InstallUtil EventLogSourceInstaller.dll is doing this work.

I recommend doing the "code it up" version, and using the RegistryKey and the Expandable-String-Value as VERIFICATION it worked....and not try to manually do it. 

Because:

InstallUtil EventLogSourceInstaller.dll

may have done something else I wasn't aware of.

I hope this helps somebody.....I was trying to give rights, and everything else under the sun like many others have tried as well.

 

PS

Here is the equivalent of doing the "First Approach" in the MS KB article.

 

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\Enterprise Library Logging]

 

Save that as a .reg file and import it.