By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,292 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.ExceptionHan dling
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.ExceptionHan dling.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.ExceptionHan dling.Logging.LoggingExceptionHandler,
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling.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\bi n\Debug\WindowsApplication1.vshost.exe.config"
Line=47
Message="The type
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling.Logging.LoggingExceptionHandler,
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling.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\bi n\Debug\WindowsApplication1.vshost.exe.config line 47)"
Source="System.Configuration"
StackTrace:
at System.Configuration.BaseConfigurationRecord.Evalu ateOne(String[]
keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord,
SectionRecord sectionRecord, Object parentResult)
at
System.Configuration.BaseConfigurationRecord.Evalu ate(FactoryRecord
factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean
getLkg, Boolean getRuntimeObject, Object& result, Object&
resultRuntimeObject)
at
System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String
configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject,
Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at
System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String
configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject,
Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at
System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String
configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject,
Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSe ction(String
configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.BaseConfigurationRecord.GetSe ction(String
configKey)
at
System.Configuration.ClientConfigurationSystem.Sys tem.Configuration.Internal.IInternalConfigSystem.G etSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSecti on(String
sectionName)
at
Microsoft.Practices.EnterpriseLibrary.Common.Confi guration.SystemConfigurationSourceImplementation.G etSection(String sectionName)
at
Microsoft.Practices.EnterpriseLibrary.Common.Confi guration.SystemConfigurationSource.GetSection(Stri ng sectionName)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling.Configuration.ExceptionHandlingSettings.GetE xceptionHandlingSettings(IConfigurationSource
configurationSource)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling.ExceptionHandlingConfigurationView.get_Excep tionHandlingSettings()
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling.ExceptionHandlingConfigurationView.GetExcept ionPolicyData(String policyName)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling.ExceptionPolicyCustomFactory.GetConfiguratio n(String id, IConfigurationSource configurationSource)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling.ExceptionPolicyCustomFactory.CreateObject(IB uilderContext
context, String name, IConfigurationSource configurationSource,
ConfigurationReflectionCache reflectionCache)
at
Microsoft.Practices.EnterpriseLibrary.Common.Confi guration.ObjectBuilder.ConfiguredObjectStrategy.Bu ildUp(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.SingletonStrateg y.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.Confi guration.ObjectBuilder.ConfigurationNameMappingStr ategy.BuildUp(IBuilderContext
context, Type t, Object existing, String id)
at
Microsoft.Practices.ObjectBuilder.BuilderBase`1.Do BuildUp(IReadWriteLocator
locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[]
transientPolicies)
at
Microsoft.Practices.ObjectBuilder.BuilderBase`1.Bu ildUp(IReadWriteLocator
locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[]
transientPolicies)
at
Microsoft.Practices.ObjectBuilder.BuilderBase`1.Bu ildUp[TTypeToBuild](IReadWriteLocator
locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
at
Microsoft.Practices.EnterpriseLibrary.Common.Confi guration.ObjectBuilder.EnterpriseLibraryFactory.Bu ildUp[T](IReadWriteLocator
locator, String id, IConfigurationSource configurationSource)
at
Microsoft.Practices.EnterpriseLibrary.Common.Confi guration.ObjectBuilder.LocatorNameTypeFactoryBase` 1.Create(String name)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling.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\Fo rm1.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(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow( HandleRef hWnd,
Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolea n value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.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.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
-----------------------------------------------------------------------------------
--
Thanks in advance for your replies!
Jun 11 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.