Exception when calling Logger.IsLoggingEnabled

Topics: Logging Application Block
Aug 27, 2010 at 2:03 PM

I am getting an exception when calling the method

The inner exepction message is:

Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type LogWriter cannot be constructed. You must configure the container to supply this value.
-----------------------------------------------
At the time of the exception, the container was:

  Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)

It appears I have not configured something correctly, any ideas?

This is my config file. It is part of a class library and yes I have added references in the library to the Logging dll.

<!--l version="1.0" encoding="utf-8"-->
<?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="Application" machineName="." traceOutputOptions="DateTime, Callstack"
                filter="Error" />
            <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                fileName="trace.log" formatter="Text Formatter" traceOutputOptions="LogicalOperationStack, DateTime, Callstack" />
        </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="Off" name="All Events" />
            <notProcessed switchValue="Off" name="Unprocessed Category" />
            <errors switchValue="Error" name="Logging Errors &amp; Warnings">
                <listeners>
                    <add name="Flat File Trace Listener" />
                </listeners>
            </errors>
        </specialSources>
    </loggingConfiguration>
    <connectionStrings>
        <add name="My.MySettings.WFCommonConnectionString" connectionString="Data Source=AUV692.auburn.auto.cooperintra.ctb\GENDV03;Initial Catalog=WFCommon;Integrated Security=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information" />
        </switches>
        <sharedListeners>
            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
                 initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>
</configuration>

<!-- This section defines the logging configuration for My.Application.Log --><!-- Uncomment the below section to write to the Application Event Log --><!--<add name="EventLog" />--><!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log --><!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME" /> -->
<!-- This section defines the logging configuration for My.Application.Log --> <!-- Uncomment the below section to write to the Application Event Log --> <!--<add name="EventLog" />--> <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log --> <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME" /> -->

 

 

 

 

 

 

Aug 31, 2010 at 3:10 AM

Hi TheLastSteve,

From the exception encountered it looks to me that it was unable to read the logging configuration. You mentioned that your config is part of a class library project the question is how are you reading from it?

Note that class libraries don't own configuration files. Configuration file should be placed in an executable project (console, windows, web, webservice).

In your case see if the approach discussed in Tom Hollander's blog may be useful for you http://blogs.msdn.com/b/tomholl/archive/2006/04/02/entlib2externalconfig.aspx.

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 31, 2010 at 11:08 AM

thanks for the feedback.

Looking at the link you posted I see it is referencing the 2.0 framework. I am using the 4.0 Framework. (Don't know yet if this is an issue as it relates to my problem)

I also set the app.config file to allways copy to the output folder and verified it is in the path. Still experiencing the same problem.

I will continue to investigate.

Again, Thanks for your assistance.

Aug 31, 2010 at 11:23 AM

I added a config file to my executable and it worked.

Thanks again!