Unable to Write to Event Log w/ Enterprise Library 2.0 in Win App



Hi,

Thanks in advance for reading this.

Not sure where to post this question, but I hope someone in here can help.

Trying to write to Event Log in VS 2005 (.NET 2.0) using Enterprise Library
2.0
on a XP Pro SP2 Machine

Setup a basic Windows app in Form load's:


Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports Microsoft.Practices.EnterpriseLibrary.Logging
Imports Microsoft.Practices.EnterpriseLibrary.Common

Public Class Form1

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Try
Logger.Write("Writing to EventLog", "Sample Exception", 0, 100,
TraceEventType.Information, "Sample Title")

Process()
Catch ex As Exception
ExceptionPolicy.HandleException(ex, "Sample Exception Policy")
End Try

End Sub

' Routine that causes an exception to be thrown
Private Sub Process()
Throw New Exception("Original Generated Exception")
End Sub

End Class

-----------------------------------------------------------------------------------

Here's how it looks like with the Enterprise Lib Config tool for the
Execption and Logging blocks:


Exception Handling Application Block
Sample Exception Policy
Name: Sample Exception Policy
Exception
PostHandlingAction: NotifyRethrow
Logging Handler
EVentID: 100
FormaterType:
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter
LogCategory: Sample Exception
Name: Logging Handler
Priority: 0
Severity: Error
Title: Enterprise Library Exception Handling - Sample App


Logging Application Block
Filter
Category Sources
Sample Exception
SourceLevels: All
Formatted Eventlog TraceListener
ReferencedTraceListener: Formattted EVenlog TraceListener

Special Sources
Logging Errors & Warnings
SourceLevels: All
Formatted Eventlog TraceListener
ReferencedTraceListener: Formattted EVenlog TraceListener
Unprocessed Category
SourceLevels: All
All Events
SourceLevels: All
Trace Listeners
Formatted EVentlog TraceListener
Formatter: TExt Formatter
Log: Application
MachineName: MyWorkstationName
Name: Formatter: TExt Formatter
Source: Enterprise Library Logging - Sample App
TraceOutputOptions: None

-----------------------------------------------------------------------------------



Able to write to the Event log with the write method of the logger class.
But when the exception is thrown, the error below appears.

-----------------------------------------------------------------------------------
System.Configuration.ConfigurationErrorsException was unhandled
BareMessage="The type
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=123456789012345b from
configuration could not be created."
Filename="C:\Visual Studio 2005\Projects\Windows
Desktop\WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.vshost.exe.config"
Line=47
Message="The type
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=37433583d12c9c1b from
configuration could not be created. (C:\Visual Studio 2005\Projects\Windows
Desktop\WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.vshost.exe.config line 47)"
Source="System.Configuration"
StackTrace:
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[]
keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord,
SectionRecord sectionRecord, Object parentResult)
at
System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord
factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean
getLkg, Boolean getRuntimeObject, Object& result, Object&
resultRuntimeObject)
at
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject,
Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject,
Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject,
Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String
configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.BaseConfigurationRecord.GetSection(String
configKey)
at
System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String
sectionName)
at
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSourceImplementation.GetSection(String sectionName)
at
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource.GetSection(String sectionName)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings.GetExceptionHandlingSettings(IConfigurationSource
configurationSource)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingConfigurationView.get_ExceptionHandlingSettings()
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingConfigurationView.GetExceptionPolicyData(String policyName)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.GetConfiguration(String id, IConfigurationSource configurationSource)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.CreateObject(IBuilderContext
context, String name, IConfigurationSource configurationSource,
ConfigurationReflectionCache reflectionCache)
at
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext
context, Type t, Object existing, String id)
at
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext
context, Type typeToBuild, Object existing, String idToBuild)
at
Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext
context, Type typeToBuild, Object existing, String idToBuild)
at
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext
context, Type typeToBuild, Object existing, String idToBuild)
at
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext
context, Type t, Object existing, String id)
at
Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator
locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[]
transientPolicies)
at
Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator
locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[]
transientPolicies)
at
Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp[TTypeToBuild](IReadWriteLocator
locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
at
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator
locator, String id, IConfigurationSource configurationSource)
at
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.LocatorNameTypeFactoryBase`1.Create(String name)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName)
at WindowsApplication1.Form1.Form1_Load(Object sender, EventArgs e)
in C:\Visual Studio 2005\Projects\Windows
Desktop\WindowsApplication1\WindowsApplication1\Form1.vb:line 13
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd,
Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
-----------------------------------------------------------------------------------
--
Thanks in advance for your replies!
.



Relevant Pages

  • Re: App_data - ASPNETDB.MDF
    ... is only because I want my site work, without exception. ... Server Error in '/' Application. ... serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Unable to Write to EventLog w/ Enterprise Libary 2.0
    ... ExceptionPolicy.HandleException(ex, "Sample Exception Policy") ... keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, ... configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, ... context, String name, IConfigurationSource configurationSource, ...
    (microsoft.public.vb.general.discussion)
  • Error tracing on page
    ... An unhandled exception occurred during the execution of the ... FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean ... System.Web.UI.Control.InitRecursive(Control namingContainer) +241 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Sharepoint 2007 - Installation Error - Failed to register SP servi
    ... --> An exception of type System.Data.SqlClient.SqlException was thrown. ... exception, Boolean breakConnection) ... RunBehavior runBehavior, String resetOptionsString) ...
    (microsoft.public.sharepoint.portalserver)
  • oma not working
    ... at System.Web.Configuration.HandlerMapping..ctor(String requestType, ... String path, String typeName, Boolean defer) ... configKey, SectionRecord section) ...
    (microsoft.public.exchange.admin)

Loading