Error while logging Error in database

Aug 1, 2014 at 11:28 AM
Hi,

I have created a sample SSIS application in which i am trying to implement Logging through Enterprise Library 5.0
I am getting the following error
Resolution of the dependency failed, type = \"Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter\", name = \"(none)\".\r\nException occurred while: while resolving.\r\nException is: InvalidOperationException - The type LogWriter cannot be constructed. You must configure the container to supply this value.\r\n-----------------------------------------------\r\nAt the time of the exception, the container was:\r\n\r\n Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)\r\n

My Cofig file as follows
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <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>
  <dataConfiguration defaultDatabase="Connection String" />
  <connectionStrings>
    <add name="Connection String" connectionString="Database=SSISODS;Data Source=localhost;Integrated Security=SSPI"
        providerName="System.Data.SqlClient" />
  </connectionStrings>
  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="Database Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              databaseInstanceName="Connection String" writeLogStoredProcName="WriteLog"
              addCategoryStoredProcName="AddCategory" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, 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>
    <logFilters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          enabled="true" name="Logging Enabled Filter" />
    </logFilters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </add>
    </categorySources>

    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </errors>

    </specialSources>
  </loggingConfiguration>
</configuration>

I have created a custom Database and added all the requires SP and tables that come in the script when we downlload the EL 5 package

My Code
LogEntry loggEntry = new LogEntry { Message = "Transformation Error", Severity = TraceEventType.Error };
Logger.Write(loggEntry);

Any help appreciated.
```
Aug 1, 2014 at 1:42 PM
When you say SSIS application do you mean a package running in SQL Server? If so then, you will need to add the Enterprise Library configuration to the appropriate config file. See: Where is my app.config for SSIS? for more info.

In any case the error does point to the configuration not being loaded at runtime so I would look to make sure that the configuration is deployed properly (e.g. web.config or myapp.exe.config).

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Aug 4, 2014 at 5:08 AM
Thanks for the reply,

I have placed all the relevent dlls required for the entLib in the folder C:\Program Files\Microsoft SQL Server\100\DTS\Binn\
and registered them to the GAC as well However facing the same issue.
About the line "make sure that the configuration is deployed properly (e.g. web.config or myapp.exe.config)."; since i am new to SSIS with EnLib, can you let me some more information on it or point to an relevent source of information.

Thanks in advance.
Aug 10, 2014 at 8:11 PM
Take a look at Where is my app.config for SSIS? for a list of configuration files (it might not be up to date but I think the version numbers would be the only difference.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Aug 11, 2014 at 4:27 AM
Thanks for the reply,

I tried modifying the config files indicated in the blog but was not able to log error in DB, i was however able to get the trace tough.
I tried the same code in a console application to test if it works fine, it did.
The only issue is SSIS.
Please correct my understanding:
In the console application, when i added a seperate config file it did not log the error, however when i modified the existing app.config to add the bloks it did sucessfully.
If this understanding is correct ... does it mean the application has to pick the details from the config and SSIS package does not have its own default config.

Is there a way where we can code the whole configuration items (Logger/db/tracer configuration) in code behind (not using the config?). If yes and my understanding is correct i can eliminate the config use and may be it might wrk.. just thinking loud.

Love to hear your comments on the above.

Thanks in advnace
Aug 11, 2014 at 4:57 AM
Yes, when running in SSIS you are running under SSIS so you will be using its configuration file (similar to when using Enterprise library within BizTalk, for example).

You are right, there is no requirement that Enterprise Library be configured using a configuration file. If you want to configure Enterprise Library programmatically you can do that using the Fluent API:
var builder = new ConfigurationSourceBuilder();

builder.ConfigureLogging()
       .WithOptions
         .DoNotRevertImpersonation()
       .LogToCategoryNamed("Security")
         .SendTo.FlatFile("Security Log File")
           .FormatWith(new FormatterBuilder()
             .TextFormatterNamed("Text Formatter")
               .UsingTemplate("Timestamp: {timestamp}...{newline})}"))
             .ToFile("security.log")
         .SendTo.EventLog("Formatted EventLog TraceListener")
            .FormatWithSharedFormatter("Text Formatter")
              .ToLog("Application")
       .LogToCategoryNamed("General")
         .WithOptions.SetAsDefaultCategory()
         .SendTo.SharedListenerNamed("Formatted EventLog TraceListener");

var configSource = new DictionaryConfigurationSource();
builder.UpdateConfigurationWithReplace(configSource);
EnterpriseLibraryContainer.Current 
  = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
Another alternative might be to have your configuration at a known location and load the configuration manually on the first call:
var configSource = new FileConfigurationSource(@"C:\Configuration\MyConfig.xml");          
EnterpriseLibraryContainer.Current 
  = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to