locked
Activation error occured while trying to get instance of type LogWriter, key "" RRS feed

  • Question

  • User1215150307 posted
    Error at defaultWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
    Error Message Activation error occured while trying to get instance of type LogWriter, key ""
     
     
    LogWriter defaultWriter;
                defaultWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
    
                //TraceManager traceMgr;
                //traceMgr = EnterpriseLibraryContainer.Current.GetInstance<TraceManager>();
    
                if (defaultWriter.IsLoggingEnabled())
                {
                    Dictionary<string, object> exProperties = new Dictionary<string, object>();
                    exProperties.Add("Login", DateTime.Now.ToString("dd/MM/yyyy") + " " + Login_TextBox.Text + " Login");
                    // Create a LogEntry using the constructor parameters. 
                    LogEntry entry1 = new LogEntry("LogEntry with category, priority, event ID, severity, and title.", "General", 8, 9006, TraceEventType.Error, "Logging Block Examples", exProperties);
                    defaultWriter.Write(entry1);
                    //defaultWriter.Write(DateTime.Now.ToString("dd/MM/yyyy") + " " + Login_TextBox.Text + " Login");
                }
     
    <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="D:\TraceOutput.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>
    Wednesday, June 22, 2011 10:03 PM

Answers

All replies

  • User1621523629 posted

    Hi,

    You should set the default data base in DataConfiguration:

    <dataConfiguration defaultDatabase="MyDB1" />

    <connectionStrings>
    <add name="MyDB1" connectionString="Data Source=myServer;Initial Catalog=mydb;User Id=Username1;Password=password1;"
    providerName="System.Data.SqlClient" />

    </connectionStrings>

    Otherwise you should specify the database conection string name:

          defaultWriter = EnterpriseLibraryContainer.Current.GetInstance<Database>("MyDB1");

    Best Regards,

    Gjorgji Dimitrov

    Wednesday, June 22, 2011 10:24 PM
  • User1215150307 posted

    if i write it into a text file, how to set?

    Wednesday, June 22, 2011 10:40 PM
  • User1621523629 posted

    Hi,

    I guess you are using Enterrise Library 5.0, here is a short tutorial hot to set the library to log into text file.

    http://sanjivblog.wordpress.com/2011/05/24/how-to-use-enterprise-libraryel-for-logging/

    Best Regards,

    Gjorgji

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 1, 2011 10:29 AM