Quantcast
Channel: patterns & practices – Enterprise Library
Viewing all 1928 articles
Browse latest View live

New Post: Logging with MS Enterprise Library 5.0

$
0
0
HI i'm using Microsoft Enterprise library 5.0.

I store the Activity & Exception Log in database using database trace Listener.

i got following Error in database table in Message collumn.

Tracing to LogSource 'General' failed. Processing for other sources will continue. See summary information below for more information. Should this problem persist, stop the service and check the configuration file(s) for possible error(s) in the configuration of the categories and sinks.
__My web config file is:-__
<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=null"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
        databaseInstanceName="TestConnection" writeLogStoredProcName="WriteLog"
        addCategoryStoredProcName="General" formatter="Text Formatter"
        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=null"
        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="Database Trace 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="Database Trace Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

my Connection String is:-


<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-CRUD-20130618172811;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-CRUD-20130618172811.mdf"
      providerName="System.Data.SqlClient" />
    <add name="TestConnection" connectionString="Data Source=servername;Initial Catalog=Logging;Integrated Security=true"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
how to solve ?

New Post: Logging with MS Enterprise Library 5.0

$
0
0
See summary information below for more information
Is there any more information in the table? The exact error that occurred should be logged which should help pinpoint the exact issue. Also, you should change the errors special source to not use the Database Trace Listener and instead use another trace listener such as a flat file trace listener. This is because if writing the LogEntry to the database fails, it is quite possible that attempting to write the error information about why the write failed to the database again will also fail.

Also, just curious if you are using a custom built unsigned version of Enterprise Library (since the PublicKeyToken's are null)?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Logging with MS Enterprise Library 5.0

New Post: Referencing error

$
0
0
Hi,

After I successfully referenced(Addess binaries from Add Reference) Data and Common libararies, upon building the project I recieve "Type 'DatabaseProviderFactory' is not defied" and "Type 'Database' is not defined."

I am using Visual Studio 2010, Enterprise Library 6.0 and SQL Server 2008 R2

This is what my code looks like
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.Common.Configuration
Imports Microsoft.Practices.EnterpriseLibrary.Common

Public Class cDBServer

    Private DBFactory As DatabaseProviderFactory
    Private defaultDB As Database = DBFactory.Create("SAYACORESQL")
    ...
Any reason why is this happening? Any solutions would be appreciated.

Fersad

New Post: Referencing error

$
0
0
The issue occurs because Enterprise Library 6 targets .NET 4.5 while Visual Studio 2010 can only target .NET 4.0. If you want to use Enterprise Library 6 then you should use Visual Studio 2012 and target .NET 4.5. If you are using Visual Studio 2010 then you can use Enterprise Library 5.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Referencing error

$
0
0
I moved back to EntLib 5.0 and everything works.

Thanks Randy!

New Post: ConfigurationSourceBuilder doesn't update default config

$
0
0
Hi,

Following code is executed successfully but defaultDB's connection string doesn't change.
Public Sub New(strUserName As String, strPassword As String, strServer As String, strSchema As String)
        UserName = strUserName
        Password = strPassword
        Server = strServer
        Schema = strSchema
        Dim builder = New ConfigurationSourceBuilder()
        builder.ConfigureData() _
            .ForDatabaseNamed("SAYACORESQL") _
              .AsDefault() _
              .ThatIs.ASqlDatabase() _
              .WithConnectionString(ConnString) 'Return connection string based on parameters

        Dim configSource = New DictionaryConfigurationSource()
        builder.UpdateConfigurationWithReplace(configSource)
        EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource)
      
    End Sub
I am trying to programatically change the database App is using. What is it I am missing?

Fersad

New Post: why logging code need hold file handle

$
0
0
Thanks for the explanation, Randy.

I want to dispatch log with category dynamically. For example, i only have category 1 logs at first, and i would write all logs to "1.log" file. Then i have category 2 logs, i need all category 2 logs to "2.log" file while category 1 logs still write to "1.log" file. When more categories come, the program should be able to dispatch logs by category without changing any code or config. Because, after product goes online, it is inconvenient to do either.

In my understanding, the logging blocking is not flexible enough to do so. Am i right?

New Post: why logging code need hold file handle

$
0
0
You can definitely do what you want using programmatic configuration. Here's an example with Enterprise Library 6 that uses a dictionary to store a separate LogWriter associated with each category:
publicclass MyLogWriter
    {
        privatestatic ConcurrentDictionary<string, LogWriter> logWriters = 
            new ConcurrentDictionary<string, LogWriter>();

        publicvoid Write(string message, string category)
        {
            LogWriter logger = logWriters.GetOrAdd(category,
                (c) =>
                {
                    LoggingConfiguration config = new LoggingConfiguration();
                    config.AddLogSource(category,
                        SourceLevels.All,
                        true,
                        new FlatFileTraceListener(string.Format(@"c:\Logs\{0}.txt", category)));
                    returnnew LogWriter(config);
                });

            logger.Write(message);
        }
    }
The use of ConcurrentDictionary should make the above thread safe. The above seems like the best approach if thread safety is a concern (there are many other ways I can think of but locking could get messy).

Or instead of creating your own Write method you could create your own factory using a similar approach:
publicstaticclass MyLogWriterFactory
    {
        privatestatic ConcurrentDictionary<string, LogWriter> logWriters =
            new ConcurrentDictionary<string, LogWriter>();

        publicstatic LogWriter Create(string category)
        {
            return logWriters.GetOrAdd(category,
                (c) =>
                {
                    LoggingConfiguration config = new LoggingConfiguration();
                    config.AddLogSource(category,
                        SourceLevels.All,
                        true,
                        new FlatFileTraceListener(string.Format(@"c:\Logs\{0}.txt", category)));
                    config.DefaultSource = category;
                    returnnew LogWriter(config);
                });
        }
    }


    MyLogWriterFactory.Create("category1").Write("Category 1 message");
    MyLogWriterFactory.Create("category2").Write("Category 2  message");
I made the factory class static but you could make it a singleton.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Enterprise Library 5.0 logging application fluent configuration

$
0
0
hi!
I am using fluent to configure the logging application block via source.
Tracelistener is a custom database tracerlistener (based on the one in a Hands On Lab I think). As a Fallback a Flat File Listener is configured.
Every thing works fine so far but one problem is left:
If a category appears that is not known i don't want the not mapped exception i want it to be added. As far as my research goes this could be archieved by
<notProcessed switchValue="off" name="Unprocessed Category" />
so 2 questions:
-- is this correct?
-- How do I achive this using fluent. I tried to find info about this quite for a while now. Or am I totally wrong with this

Not directly relevant but this is my config so far (left away the parameter setup for the custom trace listener because it's not part of the problem):
        builder.ConfigureLogging()
            .WithOptions
            .DoNotRevertImpersonation()
            .LogToCategoryNamed("General")
            .WithOptions
            .SetAsDefaultCategory()
            .SendTo
                .Custom<ExtendedFormattedDatabaseTraceListener>("Database Listener").UsingInitData(tracerParametersAsString)
                    .FormatWith(formatterBuilder)

            .SpecialSources
                .LoggingErrorsAndWarningsCategory
                    .SendTo
                        .FlatFile("Fallback Log file")
                            .FormatWith(formatterBuilder)
                            .ToFile(_fallbackFilePath)
            .SendTo.SharedListenerNamed("Database Listener");
Thanks premilary for all ideas/solutions/suggestions

New Comment on "EntLib6"

$
0
0
Is there any plan for Enterprise library 6.0 and Unity 3.0 hands-on labs? It would be nice to have some decent example of modular application which loads the modules and represent a pluggable architecture. I know that MEF is designed for that. But how can it be done with Unity 3.0 in combination with Enterprise library 6. We spent a lot of time to find more information on internet but ...with no result. Most of the examples/blogposts are talking about Autofac IModule and some old one about Prism. We appreciate the P&P team effort and love to use these libraries in our large applications, but the lack of information and examples on large scale applications is forcing us to just pass :-( Behnam

New Post: Keep getting activation error occured ... Error

$
0
0
Hi,

I have configured an app.config file to connect to my SQL Server 2008 Database. It was working before but now I keep getting activation error occured while trying to get instance of type Database error. I reviewed my .config file and it seems OK. By the way, .config file is in another project which produces a library that I use in another project (Side by Side projects).

Here is my .config file
<?xml version="1.0" encoding="utf-8" ?>
<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="false" />
    </configSections>
    <dataConfiguration defaultDatabase="Core" />
    <connectionStrings>
        <add name="Core" connectionString="Server=******\******;Database=******;User Id=**;Password=*******;"
            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>
Any help would be apperciated.

Fersad.

New Post: Enterprise Library 5.0 logging application fluent configuration

$
0
0
The SpecialSources.UnprocessedCategory (<notProcessed> in xml) let's you send unprocessed categories to a trace listener. This is not set by default. Another setting which is true by default is to warn if no categories match (logWarningsWhenNoCategoriesMatch attribute in xml). You can turn this off using the fluent interface by using DoNotLogWarningsWhenNoCategoryExists():
        builder.ConfigureLogging()
            .WithOptions
            .DoNotRevertImpersonation()
            .DoNotLogWarningsWhenNoCategoryExists()
            .LogToCategoryNamed("General")
            .WithOptions
            .SetAsDefaultCategory()
            .SendTo
                .Custom<ExtendedFormattedDatabaseTraceListener>("Database Listener").UsingInitData(tracerParametersAsString)
                    .FormatWith(formatterBuilder)

            .SpecialSources
                .LoggingErrorsAndWarningsCategory
                    .SendTo
                        .FlatFile("Fallback Log file")
                            .FormatWith(formatterBuilder)
                            .ToFile(_fallbackFilePath)
            .SendTo.SharedListenerNamed("Database Listener");
With the above configuration you should only see entries written for categories you have defined.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Custom db with Enterprise Library 6

$
0
0
Hi all,
I would like to configure Enterprise Library 6 in order to let me log on a custom database (not the one generated with Microsoft sql scripts). How can i do it?

Created Unassigned: The type LogWriter cannot be construct ed. You must configure the container to supply this value. [33771]

$
0
0
Unhandled Exception: Microsoft.Practices.ServiceLocation.ActivationException: Ac
tivation error occured while trying to get instance of type LogWriter, key "" --
-> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the depend
ency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", n
ame = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type LogWriter cannot be construct
ed. You must configure the container to supply this value.

<?xml version="1.0"?>
<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" />
<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" />
</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="" machineName="." traceOutputOptions="None" />
<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="D:\New folder\UploadPath\LogFile.txt" formatter="Text Formatter"
traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack" />
<add name="Flat File Trace Listener 2" 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="D:\New folder\UploadPath\trace.log" formatter="Text Formatter"
traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack" />
<add name="Errors" 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="D:\New folder\UploadPath\Error.log" formatter="Text Formatter" />
<add name="Information" 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="D:\New folder\UploadPath\Information.log" formatter="Text Formatter" />
</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="Flat File Trace Listener" />
<add name="Errors" />
<add name="Information" />
</listeners>
</add>
<add switchValue="All" name="Error">
<listeners>
<add name="Flat File Trace Listener 2" />
</listeners>
</add>
<add switchValue="All" name="Information">
<listeners>
<add name="Flat File Trace Listener 2" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="Information" name="Logging Errors &amp; Warnings">
<listeners>
<add name="Flat File Trace Listener 2" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<dataConfiguration defaultDatabase="DefaultConnectionString">
<providerMappings>
<add databaseType="EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null"
name="EntLibContrib.Data.OdpNet" />
</providerMappings>
</dataConfiguration>
<connectionStrings>
<add name="DefaultConnectionString" connectionString="Data Source=(DESCRIPTION=(LOAD_BALANCE=no)(FAILOVER=ON)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=ABC.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=ABC.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ABC.com))); User Id=abc;Password=abc;Persist Security Info=True;"
providerName="EntLibContrib.Data.OdpNet" />
</connectionStrings>
<appSettings>
<add key="DirectFileDownload" value="true" />
<add key="EnableInformationLogging" value="true" />
<add key="LogService" value="true" />
<add key="EnableTextFileErrorLog" value="1" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.112.2.0" newVersion="2.112.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.Unity.Interception" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.505.0" newVersion="2.0.414.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Common" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.505.0" newVersion="5.0.414.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.505.0" newVersion="2.0.414.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.Unity.Configuration" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.505.0" newVersion="2.0.414.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.PolicyInjection" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.414.0" newVersion="5.0.414.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.505.0" newVersion="5.0.414.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Validation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.414.0" newVersion="5.0.414.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Logging" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.505.0" newVersion="5.0.414.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.da

New Post: Getting a Microsoft.Practices.ServiceLocation.ActivationException when logging exception to database.

$
0
0
I have been using Entlib 5 (v5.0.505.0) to log exceptions to the Event log and this works well. However I have a need to now log exceptions to the Logging database (created with the script provided with the source code), and it is failing every time, giving me a Microsoft.Practices.ServiceLocation.ActivationException with the message:
Activation error occured while trying to get instance of type ExceptionPolicyImpl, key "Contractor Competencies Exception Policy"
This exception has an inner exception of type Microsoft.Practices.Unity.ResolutionFailedException with the message:
Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl", name = "Contractor Competencies Exception Policy".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.
This is turn has an inner exception of type System.InvalidOperationException with the message:
The type Database cannot be constructed. You must configure the container to supply this value.
This exception is thrown when I execute the code:
if ( ExceptionPolicy.HandleException(ex, Logger.ExceptionPolicy) )
{
 throw;
}
This is inside a catch block and Logger.ExceptionPolicy returns a string that exactly matches the configured value.

I have looked at many posts about this error and have implemented whatever recommendations I can find such as default database and so on but it has not fixed my issue. I have project references to EnterpriseLibrary.Common, Data, ExceptionHandling, ExceptionHandling.Logging, Logging, Logging.Database, ObjectBuilder2, ServiceLocation and Unity.

If I change back to the EventLog listener it works as expected.

This is my enitre config file:
<?xml version="1.0"?>
<configuration>
 <configSections>
  <section name="loggingConfiguration"
     type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
     requirePermission="true" />
  <section name="exceptionHandling"
     type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
     requirePermission="true" />
  <section name="dataConfiguration"
     type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
     requirePermission="false" />
 </configSections>
 <loggingConfiguration name="Logging Application Block"
        tracingEnabled="true"
        defaultCategory="General"
        logWarningsWhenNoCategoriesMatch="true">
  <listeners>
   <add source="Contractor Competencies"
     formatter="Text Formatter"
     log="Application"
     machineName=""
     listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
     traceOutputOptions="Callstack"
     filter="All"
     type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
     name="Formatted EventLog TraceListener"/>
   <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
     listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
     databaseInstanceName="LoggingDb"
     writeLogStoredProcName="WriteLog"
     addCategoryStoredProcName="AddCategory"
     formatter="Text Formatter" 
     name="Formatted Database TraceListener" />
  </listeners>
  <formatters>
   <add template="*Shortened for space reasons*"
     type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
     name="Text Formatter" />
  </formatters>
  <categorySources>
   <add switchValue="All"
     name="General">
    <listeners>
     <add name="Formatted Database TraceListener" />
    </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="Formatted Database TraceListener"/>
    </listeners>
   </errors>
  </specialSources>
 </loggingConfiguration>
 <exceptionHandling>
  <exceptionPolicies>
   <add name="Contractor Competencies Exception Policy">
    <exceptionTypes>
     <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
       postHandlingAction="ThrowNewException"
       name="GeneralException">
      <exceptionHandlers>
       <add logCategory="General"
         eventId="100"
         severity="Error"
         title="Enterprise Library Exception Handling"
         formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
         priority="0"
         useDefaultLogger="false"
         type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
         name="Logging Handler"/>
       <add exceptionMessage="An error has occurred. If the problem persists, please contact IS Support on extension 6654."
         exceptionMessageResourceName=""
         exceptionMessageResourceType=""
         replaceExceptionType="System.ApplicationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
         type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
         name="Replace Handler"/>
      </exceptionHandlers>
     </add>
    </exceptionTypes>
   </add>
  </exceptionPolicies>
 </exceptionHandling>
 <dataConfiguration defaultDatabase="LoggingDb" />
 <connectionStrings>
  <add name="LoggingDb"
    connectionString="Password=******;User ID=LoggingUser;Initial Catalog=Logging;Data Source=TSTDVP01\DevSQL"
    providerName="System.Data.SqlClient" />
 </connectionStrings>
</configuration>

New Post: Keep getting activation error occured ... Error

$
0
0
The error usually means that there is a configuration issue. The configuration needs to be in the app.config or web.config of the application . So if you have the Enterprise Library configuration in a config file in another project the config information will need to be placed in the config file of the application project, or loaded through some other means (programmatic, redirected sections, file configuration source, etc.).

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Getting a Microsoft.Practices.ServiceLocation.ActivationException when logging exception to database.

$
0
0
The message usually points to the configuration being invalid but the configuration looks OK -- it works fine in a test app. So there must be some other issue with the setup or the environment.

It might be easier if you could upload a small sample application that demonstrates the problem.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Enterprise Library 5.0 logging application fluent configuration

$
0
0
Thanks for your quick answer.
Works fine now.

Updated Wiki: EntLib6 Sample Projects

$
0
0

Enterprise Library V6 Sample Projects

The following sample projects illustrate various Enterprise Library concepts and techniques.

Custom Database Trace Listener Sample

Description

This sample project shows a sample of a Custom Database Trace Listener that adds an additional column to the out of the boxFormattedDatabaseTraceListener.  The CustomDatabaseTraceListener will check the LogEntry to see if it is a CustomLogEntry and if it is then it will add the CustomData information into the CustomData column in the [Log] table.  

The Custom Database Trace Listener also support full design time integration with the Enterprise Library configuration tool as well as support for use with Enterprise Library's Fluent API.  

Download: 

Requirements

  • Enterprise Library 6 (Assembly version 6.0.0.0).
  • Microsoft .NET Framework 4.5
  • Microsoft Visual Studio 2012
  • A database server running a database that is supported by a .NET Framework 4.5 data provider.  The provided script  does not work with SQL AZURE.  For SQL Azure support, modify the out of the box CreateLoggingDatabaseObjects.sql to include the CustomData column (as well as in stored procedures).

 

Viewing all 1928 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>