Errors with Logging in a SharePoint 2010 deployment

Topics: Logging Application Block
May 21, 2010 at 6:32 PM

I'm utilizing the Enterprise Framework Logging Module in a SharePoint 2010 project... I've found that with the same configuration I can get successful logging (email, event logs, DB, etc.) from a console test application on the SharePoint server, but when I utilize the Enterprise Library in a SharePoint solution (in this case as part of a FeatureReciever) I get the following error:

==================

Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator+LifetimeInspector", name = "(none)".
Exception occurred while: while resolving.
Exception is: MethodAccessException - LifetimeInspector..ctor()
-----------------------------------------------
At the time of the exception, the container was:

  Resolving Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator+LifetimeInspector,(none)

==================

The inner stack is:

==================

   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
   at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)
   at Microsoft.Practices.Unity.UnityContainerExtensions.Resolve[T](IUnityContainer container, ResolverOverride[] overrides)
   at Microsoft.Practices.Unity.UnityContainerExtensions.AddNewExtension[TExtension](IUnityContainer container)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity.UnityContainerExtensions.AddNewExtensionIfNotPresent[TExtension](IUnityContainer container)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator..ctor(IUnityContainer container)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet()
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current()
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer()
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(Object message, String category, Int32 priority, Int32 eventId, TraceEventType severity, String title)
   at utility.Log.WriteLogMessage(String pMessage, TraceEventType pEventType, Int32 pPriority)
   at utility.FeatureRecievers.Root.FeatureActivated(SPFeatureReceiverProperties properties)
   at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)

============================

I simplified the config as much as possible... I'm just using a Flat File Trace Listener...  Here's an excerpt of my web.config (extraneous SP stuff removed)...

============================

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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" />
    <sectionGroup name="SharePoint">
      .   
      .
      .
    </sectionGroup>
  </configSections>
.
.
.
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
        <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="c:\log\trace.log" 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=31bf3856ad364e35"
            template="Timestamp: {timestamp}{newline}&#xD;&#xA;Message: {message}{newline}&#xD;&#xA;Category: {category}{newline}&#xD;&#xA;Priority: {priority}{newline}&#xD;&#xA;EventId: {eventid}{newline}&#xD;&#xA;Severity: {severity}{newline}&#xD;&#xA;Title:{title}{newline}&#xD;&#xA;Machine: {localMachine}{newline}&#xD;&#xA;App Domain: {localAppDomain}{newline}&#xD;&#xA;ProcessId: {localProcessId}{newline}&#xD;&#xA;Process Name: {localProcessName}{newline}&#xD;&#xA;Thread Name: {threadName}{newline}&#xD;&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
            name="Text Formatter" />
    </formatters>
    <categorySources>
        <add switchValue="All" name="General">
            <listeners>
                <add name="Flat File Trace Listener" />
            </listeners>
        </add>
    </categorySources>
    <specialSources>
        <allEvents switchValue="All" name="All Events">
            <listeners>
                <add name="Flat File Trace Listener" />
            </listeners>
        </allEvents>
        <notProcessed switchValue="All" name="Unprocessed Category">
            <listeners>
                <add name="Flat File Trace Listener" />
            </listeners>
        </notProcessed>
        <errors switchValue="All" name="Logging Errors &amp; Warnings">
            <listeners>
                <add name="Flat File Trace Listener" />
            </listeners>
        </errors>
    </specialSources>
</loggingConfiguration>
  <appSettings>
    <add key="FeedCacheTime" value="300" />
    <add key="FeedPageUrl" value="/_layouts/feed.aspx?" />
    <add key="FeedXsl1" value="/Style Library/Xsl Style Sheets/Rss.xsl" />
    <add key="ReportViewerMessages" value="Microsoft.SharePoint.Portal.Analytics.UI.ReportViewerMessages, Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
  </appSettings>
</configuration>

 ==============

Originally the EntLib dlls were GAC'd in the deployment, but I read where this can cause issues, so they are now in the Web App Bin folder...  To be thorough I included all the following libraries:

Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.ServiceLocation.dll
Microsoft.Practices.Unity.dll
Microsoft.Practices.Unity.Interception.dll

I've even tried changing the trust level from minimum to medium... no luck... Any ideas or direction would be greatly appreciated!

 

Thanx,

Josef Nielsen

May 24, 2010 at 2:51 AM

I copied your logging settings and worked fine on my end.  Is this placed on a configuration file for an executable project? 

Juding from the stack trace, you're using the Logger.Write method to log messages, right? Have you tried using the LogWriter API?  If not, could you please try it out, I'm curious if there's any error you will encounter using that approach and what would that be.

LogWriter logWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();

logWriter.Write(logEntry);

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@Avanade.com

May 24, 2010 at 2:20 PM

The Config is in a Web.Config for an MS SharePoint Web Project.  The Config works fine for me in a standalone Executable project, just not in a SharePoint Web project...  I am using the Logger.Write method, but will try the LogWriter API, and let you know what I get...

May 25, 2010 at 7:33 PM

I had the same problems, which led me to check my bindings... turns out I was having issues because I had not GAC'd all the required assemblies originally.  Switching back to a GAC deployment with all relavant assemblies works fine.  I still get an "Activation Error" (binding problems) when deploying through Visual Studio, but that seems to be because of some type of Actviation warpper that VS2010 used for SharePoint deployments, not an EntLib issue.  Manually activating the feature on my SharePoint Site works correctly with full logging.

Thanx,

jn

May 26, 2010 at 1:51 AM

What required assemblies are you referring?  Are you referring to entlib assemblies?  If yes, note that they need not be GAC'd to make use of them.  If you're referencing the Data and Validation assemblies from GAC, there's an issue regarding it, see this workitem in the Issue tracker for the details and workaround.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@Avanade.com

May 26, 2010 at 5:13 PM

Yes, I was talking about the entlib libraries... My custom libraries need to be GAC'd in this case, so I needed to GAC the entlib stuff as well.  I had missed a couple of the entlib required libraries for DB logging previously (ServiceLocation, Unity, Data, etc)...  I did find the workaround you specified for the Data GAC issue, and it worked perfectly.  Thanx!

Jan 20, 2011 at 10:51 PM

I am trying to implement the same setup in SharePoint 2010 and am getting this same error.

Jan 21, 2011 at 12:14 AM

Please see if this more recent thread regarding using entlib with sharepoint will help.

 

Sarah Urmeneta
Global Technologies & Solutions
Avanade, Inc.
entlib.support@Avanade.com

Jan 21, 2011 at 5:25 PM

Got it working now, thanks for that thread.

I had already run across those articles in my search on the subject, but I missed a step.

Once I put the entlib assemblies in the GAC, everything works.

Thanks for your assistance on this Sarah!