EntLib5: Loggin application block is not logged in the event log (exception: LogWriter type cannot be created) - Can anyone help?

Hi

I just configure part of the logging application block in Enterprise Library 5. I think I did it right, but did not log in the error log in the write method and gave me the following exception.

The type LogWriter cannot be constructed. You must configure the container to supply this value. 

Can someone check me out or tell me what I am missing.

First of all, I run on Windows 7 with the winforms application.

Here is my method that creates a log and you see a way to write.

 public class Logger : ILogger { public void SendTest(string test) { LogEntry log = new LogEntry(); log.EventId = 300; log.Message = test; log.Categories.Add("testing"); log.Severity = TraceEventType.Information; log.Priority = 5; Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(log); } } 

All my configs were created using the entlib5 editor, and not manually. And confirmed this si path where entlib.config

  filePath="C:\myapp\entlib.config" /> 

Here is my app.config which POINTS for my entlib.config

 <?xml version="1.0"?> <configuration> <configSections> <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /> </configSections> <enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source"> <sources> <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> <add name="File-based Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" filePath="C:\myapp\entlib.config" /> </sources> <redirectSections> <add sourceName="File-based Configuration Source" name="Redirected Section" /> </redirectSections> </enterpriseLibrary.ConfigurationSource> <startup><supportedRuntime version="v2.0.50727"/></startup></configuration> 

and here is my entlib.config

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /> </configSections> <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General"> <listeners> <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" source="Enterprise Library Logging" formatter="Text Formatter" log="" machineName="." traceOutputOptions="None" /> </listeners> <formatters> <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}" name="Text Formatter" /> </formatters> <categorySources> <add switchValue="All" name="General"> <listeners> <add name="Event Log Listener" /> </listeners> </add> </categorySources> <specialSources> <allEvents switchValue="All" name="All Events" /> <notProcessed switchValue="All" name="Unprocessed Category" /> <errors switchValue="All" name="Logging Errors &amp; Warnings"> <listeners> <add name="Event Log Listener" /> </listeners> </errors> </specialSources> </loggingConfiguration> </configuration> 

EDIT The question has been updated with the new app.config to enable

 <redirectSections> <add sourceName="File-based Configuration Source" name="Redirected Section" /> </redirectSections> 

I am still getting an error.

  Activation error occured while trying to get instance of type 

LogWriter, ""

and internal exception

Problem resolving failed, type = \ "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter \", name = \ "(none) \". \ r \ nException occurred while: while resolving. \ r \ nException: InvalidOperationException - the type LogWriter cannot be constructed. You must configure the container to deliver this value. \ R \ n ------------------------------------- ------- --- At the time the exception the container was: \ r \ n \ r \ n Solution Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, (no) \ r \ n "}

I used the EntLib configurator to create both files.

In entlib.config, I accepted the default value, as the EventLog receiver seems to be enabled.

EDIT

this is my line in the entlib.config file, the log is empty. ermm is this right?

  <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" source="Enterprise Library Logging" formatter="Text Formatter" log="" machineName="." traceOutputOptions="None" /> 

EDIT

MY Logger.write is in the dll, but my app.config / entlib.config is in the winforms application .. winforms application has a link to the dll project where I write the log.

Both dll and winforms reference

  Microsoft.Practices.EnterpriseLibrary.Logging 

and also using unit, has

  Microsoft.Practices.Unity Microsoft.Practices.Unity.Interception 
+6
logging enterprise-library
source share
1 answer

Martin, you created a file-based configuration source, but you did not redirect it to the log.

Add the following to the App.config inside the enterpriseLibrary.ConfigurationSource node:

 <redirectSections> <add sourceName="File-based Configuration Source" name="loggingConfiguration" /> </redirectSections> 

In addition, I recommend Configuration Sources Labs from the Enterprise Library 5.0 Hands-on Labs . It covers this and more complex scenarios.

+3
source share

All Articles