Last post Jul 01, 2011 10:29 AM by gjorgji
Member
78 Points
404 Posts
Jun 22, 2011 10:03 PM|Fitmation|LINK
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}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
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 & Warnings"> <listeners> <add name="Event Log Listener"/> </listeners> </errors> </specialSources> </loggingConfiguration>
260 Points
80 Posts
Jun 22, 2011 10:24 PM|gjorgji|LINK
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" />
Otherwise you should specify the database conection string name:
defaultWriter = EnterpriseLibraryContainer.Current.GetInstance<Database>("MyDB1");
Best Regards,
Gjorgji Dimitrov
Jun 22, 2011 10:40 PM|Fitmation|LINK
if i write it into a text file, how to set?
Jul 01, 2011 10:29 AM|gjorgji|LINK
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/
Gjorgji
Member
78 Points
404 Posts
Activation error occured while trying to get instance of type LogWriter, key ""
Jun 22, 2011 10:03 PM|Fitmation|LINK
Member
260 Points
80 Posts
Re: Activation error occured while trying to get instance of type LogWriter, key ""
Jun 22, 2011 10:24 PM|gjorgji|LINK
Hi,
You should set the default data base in DataConfiguration:
<dataConfiguration defaultDatabase="MyDB1" />
<connectionStrings>
<div id="DescriptionPanel" style="padding-left: 30px;"></connectionStrings></div><add name="MyDB1" connectionString="Data Source=myServer;Initial Catalog=mydb;User Id=Username1;Password=password1;"
providerName="System.Data.SqlClient" />
Otherwise you should specify the database conection string name:
Best Regards,
Gjorgji Dimitrov
Member
78 Points
404 Posts
Re: Activation error occured while trying to get instance of type LogWriter, key ""
Jun 22, 2011 10:40 PM|Fitmation|LINK
if i write it into a text file, how to set?
Member
260 Points
80 Posts
Re: Activation error occured while trying to get instance of type LogWriter, key ""
Jul 01, 2011 10:29 AM|gjorgji|LINK
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