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);

Debug.WriteLine(message);

// manually invoke the Enterprise Library logging mechanism
LogEntry logEntry = new LogEntry();
logEntry.Categories.Clear();
logEntry.Categories.Add("General");
logEntry.Priority = 5;
logEntry.Severity = TraceEventType.Information;
logEntry.Message = message;
Logger.Write(logEntry);

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=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

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

The PIAB config looks like this:


  <policyInjection>
    <policies>
      <add name="LoggingPolicy">
        <matchingRules>
          <add match="El4Wf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d51421f918ad84c5"
            type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.AssemblyMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=4.0.0.0, 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=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Method Signature Matching Rule">
            <parameters>
              <parameter name="sender" typeName="object" />
              <parameter name="e" typeName="EventArgs" />
            </parameters>
          </add>
        </matchingRules>
        <handlers>
          <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=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Logging Handler">
            <categories>
              <add name="General" />
              <add name="All" />
            </categories>
          </add>
        </handlers>
      </add>
    </policies>
  </policyInjection>


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
Hi,

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.

Fernando

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.