Performance Counter Handler / Log Call Handler

Topics: Logging Application Block, Policy Injection Application Block
Dec 12, 2007 at 12:49 AM
Has anyone ever been successful implementing Performance Counters feature off Policy Injection App Block on ASP.NET?

I've been spinning for two days and nothing's worked so far.

I'm using EntLib 3.1 installed in the GAC and my app is ASP.NET. Neither PerformanceCountersHandler nor LogCallHandler worked and I started to wonder if both can be used at all.

Thanks.
Dec 27, 2007 at 3:18 PM
Hi,

Did you run installutil on the Core and PIAB assemblies?
Do the perf counters show up in the list but have no values, or they are just missing?
Is instrumentation enabled in your app's configuration file (see ms-help://MS.VSCC.v80/MS.VSIPCC.v80/ms.EntLib.2007May/EnterpriseLibrary/html/00-190-Enabling_Instrumentation.htm)?

Fernando


bakabrain wrote:
Has anyone ever been successful implementing Performance Counters feature off Policy Injection App Block on ASP.NET?

I've been spinning for two days and nothing's worked so far.

I'm using EntLib 3.1 installed in the GAC and my app is ASP.NET. Neither PerformanceCountersHandler nor LogCallHandler worked and I started to wonder if both can be used at all.

Thanks.

Dec 27, 2007 at 5:21 PM
Thanks for the response, I finally figured it out.

I did not register the target object with PIAB Injector.... I'm a dumbo...

It's all working great now.



fsimonazzi wrote:
Hi,

Did you run installutil on the Core and PIAB assemblies?
Do the perf counters show up in the list but have no values, or they are just missing?
Is instrumentation enabled in your app's configuration file (see ms-help://MS.VSCC.v80/MS.VSIPCC.v80/ms.EntLib.2007May/EnterpriseLibrary/html/00-190-Enabling_Instrumentation.htm)?

Fernando


bakabrain wrote:
Has anyone ever been successful implementing Performance Counters feature off Policy Injection App Block on ASP.NET?

I've been spinning for two days and nothing's worked so far.

I'm using EntLib 3.1 installed in the GAC and my app is ASP.NET. Neither PerformanceCountersHandler nor LogCallHandler worked and I started to wonder if both can be used at all.

Thanks.


Jan 28, 2009 at 7:48 AM
I cannot get logging using the LogCallHandler in my asp.net application no matter what i do it seems.

The log file gets created but is always empty. I can successfully write manual log entries but with PolicyInjection it doesn't work. If i remove the LogCallHandler attribute, the log file doesn't get created but as soon as i add the attribute it does so it appears as though PolicyInjection is working with my log settings but nothing is actually written.

This is my logging config:

 <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add fileName="rolling.log" footer="----------------------------------------"
        header="----------------------------------------" rollFileExistsBehavior="Overwrite"
        rollInterval="None" rollSizeKB="0" timeStampPattern="yyyy-MM-dd"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Rolling Flat File Trace Listener" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Rolling Flat File 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="Rolling Flat File Trace Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

This is my log call handler:

[LogCallHandler(BeforeMessage = "before!"
            , AfterMessage = "after!"
            , Categories = new string[] { "General" }
            , LogBeforeCall = true
            , LogAfterCall = true
            , IncludeParameters = true
            , Severity = TraceEventType.Information
            , IncludeCallTime = true
            , IncludeCallStack = true)]

but nothing is output. I've tried to use the PIAB block in the config to target my class, namespace, etc... and the same thing occurs, log file gets created but nothing is written to it.

Anyone else have this issue?

Cheers!
Jan 28, 2009 at 9:56 AM
Hi,

I tried to use your config and your log call handler and got it to work. here is what I did.

1. Created a class that has the method that will be decorated by the Log Call Handler attribute, my class inherited from "MarshalByRefObject", because for the class to be interceptable by the policy injection app block, it must:(1) Derived from Derive from the class MarshalByRefObject. or (2) Implement an interface. Please see this link: http://msdn.microsoft.com/en-us/library/dd140038.aspx

Here is my Class:

public

class DoSomething : MarshalByRefObject
{
[
LogCallHandler(BeforeMessage = "before!", AfterMessage = "after!", Categories = new string[] { "General" }, LogBeforeCall = true, LogAfterCall = true, IncludeParameters = true,
Severity =
TraceEventType.Information, IncludeCallTime = true, IncludeCallStack = true)]
public string SayHello()
{
return "Hello";
}
}

2. Then I called the SayHello method by instantiating that class using the policy injection. Like this:

DoSomething something = PolicyInjection.Create<DoSomething>();
something.SayHello();


Hope this Helps.


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Jan 28, 2009 at 10:22 AM
Hi,

Thanks for the quick reply.

Thats pretty much identical to what i have but still an empty log file. I'm trying this in an asp.net web application. I've tried this in both an aspx and an ashx class. I've also tried version 4 and 4.1 of the enterprise library. This does seem very strange as I've never had problems with the CacheCallHandler.

Other ideas?
Jan 28, 2009 at 11:08 AM
Hi,

That is indeed strange. I tried my solution in a asp.net web application. Would you mind sending me your sample solution so i can try it?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Jan 29, 2009 at 12:24 AM
I figured it out... not sure if this is a bug with the LogCallHandler or not:

If the method that i have looks like this:

[LogCallHandler(BeforeMessage = "before!"
            , AfterMessage = "after!"
            , LogBeforeCall = true
            , LogAfterCall = true
            , IncludeParameters = true
            , Severity = TraceEventType.Information
            , IncludeCallTime = true
            , IncludeCallStack = true)]
        public string GetOtherString(string source) { ..... }

and i call this method after wrapping/creating the object with PolicyInjection with null as the parameter, the logger will create the file but not log anything at all. If i pass any string, empty or otherwise, logging occurs.

I was passing in Request.Form["myvariable"] as the parameter to my method and myvariable was empty which in turn was actually passing null to my method. Obvioulsy the work around is to check to see of Request.Form["myvariable"] exist or not before proceeding but seems as though even if null is passed to the method, the logging should still occur.
Feb 2, 2009 at 10:16 AM
I was able to repro your error in version 4.0 and 4.1.  I agree, regardless of the value of the parameter, logging should continue.  I'll log an issue for this.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Feb 10, 2009 at 3:25 AM
Just wanted to let you know that I've already logged an issue for this - http://www.codeplex.com/entlib/WorkItem/View.aspx?WorkItemId=21064


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