PIAB, SharePoint workflow,

Topics: Building and extending application blocks, Logging Application Block, Policy Injection Application Block
May 20, 2008 at 8:47 PM
Edited May 20, 2008 at 8:50 PM
I'm trying to to perform a simple policy injection of Enter/Exit from each method in an assembly that is a SharePoint (MOSS 2007) workflow.

The idea is to not have to decorate each method with a [LogCallHandler...] attribute.

Problem: I cannot get the PIAB to inject the proper Log call handler to trace the entrance and exit of each method.

I can manually write log entries "the old fashioned way" by putting code like the following inside the method, so I know my Logging to a rolling flat file is configured properly:

private void TestMethod(object sender, EventArgs e)
MethodBase mb = MethodBase.GetCurrentMethod();
string methodName = mb.Name;
Assembly asm = Assembly.GetExecutingAssembly();
bool isLoggingTurnedOn = Logger.IsLoggingEnabled();
string message = string.Format("Inside method {0}, logging is {1}, Assembly FullName = {2}"
    , methodName, isLoggingTurnedOn, asm.FullName);


// manually invoke the Enterprise Library logging mechanism
LogEntry logEntry = new LogEntry();
logEntry.Priority = 5;
logEntry.Severity = TraceEventType.Information;
logEntry.Message = message;

I used the config tool to set up two sections in the SharePoint web.config file:

<section name="policyInjection" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.PolicyInjectionSettings, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

The PIAB config looks like this:

      <add name="LoggingPolicy">
          <add match="El4Wf, Version=, Culture=neutral, PublicKeyToken=d51421f918ad84c5"
            type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.AssemblyMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Assembly Matching Rule" />
          <add match="TestMethod" ignoreCase="false" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.MethodSignatureMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Method Signature Matching Rule">
              <parameter name="sender" typeName="object" />
              <parameter name="e" typeName="EventArgs" />
          <add logBehavior="BeforeAndAfter" beforeMessage="Entering" afterMessage="Exited From"
            eventId="0" includeParameterValues="false" includeCallStack="false"
            includeCallTime="true" priority="2" severity="Information" order="0"
            type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.LogCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Logging Handler">
              <add name="General" />
              <add name="All" />

No matter what I try (AssemblyMatchingRule, MethodSignatureMatchingRule), no trace entries (via PIAB) are ever written to my rolling flat file trace log.  All I see is the "manually created" log entry that I created "the old fashioned way" via EL4's Logger class.

1. Is it the case that SharePoint (MOSS 2007) workflows and Enterprise Library 4.0's PIAB are just not meant to work together and I should either give up on the notion of trying this sort of "shotgun wedding" or live with the tedious "manual logging" technique?

2. Am I overlooking something obvious about configuring the PIAB portion of the SharePoint web.config?

3. Do I need to do something crazy like adding several dozen <SafeControl Assembly="Microsoft.Practicies.EnterpriseLibrary..... entries to the SharePoint web.config?

4. Something else entirely?

May 20, 2008 at 9:13 PM

I suggest you try a simpler scenario first to make sure it works first. You can also try Tom's effective policy viewer; while it hasn't been updated lately it's probably not hard to bring it up to date.


May 22, 2008 at 1:14 AM
Where are the objects that you want to intercept being created? If you're the one creating them, you have to be sure to use the PolicyInjection.Create or .Wrap methods. If Sharepoint is creating them for you, you're out of luck - Sharepoint doesn't know about PIAB and cannot be changed (that I know of) to use the factory method.