Activation error occured while trying to get instance of type LogWriter

40,925

Solution 1

I just wanted to add this error may be caused by another configuration issue. Make sure to look at the inner exceptions for this error. In my case it was:

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

To resolve this I had to add a providerName to my database connection string in the web.config. So the final connection string node looked like this:

 <add name="DBConn" connectionString="Data Source=ServerName;Initial Catalog=Logging;Persist Security Info=True;integrated security=True;" providerName="System.Data.SqlClient" />

Solution 2

I realized that I was trying to use Config file from within a DLL which does not work. I should be using FileConfigurationSource instead.

If I use the same App.Config from an application, it worked fine.

Solution 3

Reading the other answers to this question, and from my own experiences, in general it seems this error occurs when your application cannot read some required configuration for the Logging application block from a config file.

To add to the scenarios mentioned in previous answers, I've come across this error a couple of times:

1) In a unit test project, where I forgot to add an app.config file at all;

2) In a config file where I deleted a particular listener from the loggingConfiguration section but forgot to remove the name of the listener from the categorySource that referenced it.

Solution 4

It is missing DLL; pay attension when you place your DLL's at GAC you may need to add more DLL's to GAC . Common, Data, Logging, Logging.Database and ServiceLocation DLLS make sure they reside together in one directory

Share:
40,925
user349339
Author by

user349339

Updated on April 16, 2020

Comments

  • user349339
    user349339 about 4 years

    I am trying to using the Logging Application block of Enterprise Library 5.0 to log simple message to the Windows event log on Win XP SP3 system using:

    Logger.Write(msg);
    

    I get the "Activation error occured while trying to get instance of type LogWriter" error message when trying to log.

    Shown below is the config file used with MS Enterprise library

    <?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="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>
    
  • Sameh
    Sameh almost 13 years
    I tried placing these DLLS in GAC but still getting same error but when I place them in the application bin; the error is gone;
  • SteveCl
    SteveCl about 12 years
    always the simplest things that take the longest to solve!! Thx!
  • granadaCoder
    granadaCoder about 12 years
    I'd give you 10 Up Votes if I could. Geeze.... THANKS. Have a Great Good Friday.
  • JustAMartin
    JustAMartin about 12 years
    Thank you so much, I tried so many GAC-related solutions for this issue and nothing worked until this one.
  • The Dag
    The Dag almost 11 years
    The simplest things often take long to solve because coders only test positively and don't think about how software should behave when something is wrong!