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.Pract ices.Enterprise Library.Excepti onHandling
Imports Microsoft.Pract ices.Enterprise Library.Logging
Imports Microsoft.Pract ices.Enterprise Library.Common
Public Class Form1
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Try
Logger.Write("W riting to EventLog", "Sample Exception", 0, 100,
TraceEventType. Information, "Sample Title")
Process()
Catch ex As Exception
ExceptionPolicy .HandleExceptio n(ex, "Sample Exception Policy")
End Try
End Sub
' Routine that causes an exception to be thrown
Private Sub Process()
Throw New Exception("Orig inal 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
PostHandlingAct ion: NotifyRethrow
Logging Handler
EVentID: 100
FormaterType:
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Text ExceptionFormat ter
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
ReferencedTrace Listener: Formattted EVenlog TraceListener
Special Sources
Logging Errors & Warnings
SourceLevels: All
Formatted Eventlog TraceListener
ReferencedTrace Listener: Formattted EVenlog TraceListener
Unprocessed Category
SourceLevels: All
All Events
SourceLevels: All
Trace Listeners
Formatted EVentlog TraceListener
Formatter: TExt Formatter
Log: Application
MachineName: MyWorkstationNa me
Name: Formatter: TExt Formatter
Source: Enterprise Library Logging - Sample App
TraceOutputOpti ons: 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.Configur ation.Configura tionErrorsExcep tion was unhandled
BareMessage="Th e type
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Logg ing.LoggingExce ptionHandler,
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Logg ing,
Version=2.0.0.0 , Culture=neutral , PublicKeyToken= 123456789012345 b from
configuration could not be created."
Filename="C:\Vi sual Studio 2005\Projects\W indows
Desktop\Windows Application1\Wi ndowsApplicatio n1\bin\Debug\Wi ndowsApplicatio n1.vshost.exe.c onfig"
Line=47
Message="The type
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Logg ing.LoggingExce ptionHandler,
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Logg ing,
Version=2.0.0.0 , Culture=neutral , PublicKeyToken= 37433583d12c9c1 b from
configuration could not be created. (C:\Visual Studio 2005\Projects\W indows
Desktop\Windows Application1\Wi ndowsApplicatio n1\bin\Debug\Wi ndowsApplicatio n1.vshost.exe.c onfig line 47)"
Source="System. Configuration"
StackTrace:
at System.Configur ation.BaseConfi gurationRecord. EvaluateOne(Str ing[]
keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord,
SectionRecord sectionRecord, Object parentResult)
at
System.Configur ation.BaseConfi gurationRecord. Evaluate(Factor yRecord
factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean
getLkg, Boolean getRuntimeObjec t, Object& result, Object&
resultRuntimeOb ject)
at
System.Configur ation.BaseConfi gurationRecord. GetSectionRecur sive(String
configKey, Boolean getLkg, Boolean checkPermission , Boolean getRuntimeObjec t,
Boolean requestIsHere, Object& result, Object& resultRuntimeOb ject)
at
System.Configur ation.BaseConfi gurationRecord. GetSectionRecur sive(String
configKey, Boolean getLkg, Boolean checkPermission , Boolean getRuntimeObjec t,
Boolean requestIsHere, Object& result, Object& resultRuntimeOb ject)
at
System.Configur ation.BaseConfi gurationRecord. GetSectionRecur sive(String
configKey, Boolean getLkg, Boolean checkPermission , Boolean getRuntimeObjec t,
Boolean requestIsHere, Object& result, Object& resultRuntimeOb ject)
at System.Configur ation.BaseConfi gurationRecord. GetSection(Stri ng
configKey, Boolean getLkg, Boolean checkPermission )
at System.Configur ation.BaseConfi gurationRecord. GetSection(Stri ng
configKey)
at
System.Configur ation.ClientCon figurationSyste m.System.Config uration.Interna l.IInternalConf igSystem.GetSec tion(String sectionName)
at System.Configur ation.Configura tionManager.Get Section(String
sectionName)
at
Microsoft.Pract ices.Enterprise Library.Common. Configuration.S ystemConfigurat ionSourceImplem entation.GetSec tion(String sectionName)
at
Microsoft.Pract ices.Enterprise Library.Common. Configuration.S ystemConfigurat ionSource.GetSe ction(String sectionName)
at
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Conf iguration.Excep tionHandlingSet tings.GetExcept ionHandlingSett ings(IConfigura tionSource
configurationSo urce)
at
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Exce ptionHandlingCo nfigurationView .get_ExceptionH andlingSettings ()
at
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Exce ptionHandlingCo nfigurationView .GetExceptionPo licyData(String policyName)
at
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Exce ptionPolicyCust omFactory.GetCo nfiguration(Str ing id, IConfigurationS ource configurationSo urce)
at
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Exce ptionPolicyCust omFactory.Creat eObject(IBuilde rContext
context, String name, IConfigurationS ource configurationSo urce,
ConfigurationRe flectionCache reflectionCache )
at
Microsoft.Pract ices.Enterprise Library.Common. Configuration.O bjectBuilder.Co nfiguredObjectS trategy.BuildUp (IBuilderContex t
context, Type t, Object existing, String id)
at
Microsoft.Pract ices.ObjectBuil der.BuilderStra tegy.BuildUp(IB uilderContext
context, Type typeToBuild, Object existing, String idToBuild)
at
Microsoft.Pract ices.ObjectBuil der.SingletonSt rategy.BuildUp( IBuilderContext
context, Type typeToBuild, Object existing, String idToBuild)
at
Microsoft.Pract ices.ObjectBuil der.BuilderStra tegy.BuildUp(IB uilderContext
context, Type typeToBuild, Object existing, String idToBuild)
at
Microsoft.Pract ices.Enterprise Library.Common. Configuration.O bjectBuilder.Co nfigurationName MappingStrategy .BuildUp(IBuild erContext
context, Type t, Object existing, String id)
at
Microsoft.Pract ices.ObjectBuil der.BuilderBase `1.DoBuildUp(IR eadWriteLocator
locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[]
transientPolici es)
at
Microsoft.Pract ices.ObjectBuil der.BuilderBase `1.BuildUp(IRea dWriteLocator
locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[]
transientPolici es)
at
Microsoft.Pract ices.ObjectBuil der.BuilderBase `1.BuildUp[TTypeToBuild](IReadWriteLoca tor
locator, String idToBuild, Object existing, PolicyList[] transientPolici es)
at
Microsoft.Pract ices.Enterprise Library.Common. Configuration.O bjectBuilder.En terpriseLibrary Factory.BuildUp[T](IReadWriteLoca tor
locator, String id, IConfigurationS ource configurationSo urce)
at
Microsoft.Pract ices.Enterprise Library.Common. Configuration.O bjectBuilder.Lo catorNameTypeFa ctoryBase`1.Cre ate(String name)
at
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Exce ptionPolicy.Get ExceptionPolicy (Exception exception, String policyName)
at
Microsoft.Pract ices.Enterprise Library.Excepti onHandling.Exce ptionPolicy.Han dleException(Ex ception exceptionToHand le, String policyName)
at WindowsApplicat ion1.Form1.Form 1_Load(Object sender, EventArgs e)
in C:\Visual Studio 2005\Projects\W indows
Desktop\Windows Application1\Wi ndowsApplicatio n1\Form1.vb:lin e 13
at System.EventHan dler.Invoke(Obj ect sender, EventArgs e)
at System.Windows. Forms.Form.OnLo ad(EventArgs e)
at System.Windows. Forms.Form.OnCr eateControl()
at System.Windows. Forms.Control.C reateControl(Bo olean fIgnoreVisible)
at System.Windows. Forms.Control.C reateControl()
at System.Windows. Forms.Control.W mShowWindow(Mes sage& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.Container Control.WndProc (Message& m)
at System.Windows. Forms.Form.WmSh owWindow(Messag e& m)
at System.Windows. Forms.Form.WndP roc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.SafeNativ eMethods.ShowWi ndow(HandleRef hWnd,
Int32 nCmdShow)
at System.Windows. Forms.Control.S etVisibleCore(B oolean value)
at System.Windows. Forms.Form.SetV isibleCore(Bool ean value)
at System.Windows. Forms.Control.s et_Visible(Bool ean value)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext context)
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[] commandLine)
at WindowsApplicat ion1.My.MyAppli cation.Main(Str ing[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile, Evidence
assemblySecurit y, String[] args)
at Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
-----------------------------------------------------------------------------------
--
Thanks in advance for your replies!