Where do Unity log errors?

Jul 26, 2011 at 3:50 PM

Hi Forum

I'm trying to configure unity to use a callhandler - more specifically PerformanceCounterCallHandler.

I think my config looks ok, but I'm not getting any errors and it is not working.

Where would I go look for errors that Unity report?

Jul 27, 2011 at 7:23 AM

Hi,

I'm afraid that PerformanceCounterCallHandler doesn't throw any errors. If there is something wrong, it will not just work. Can you look at this thread if their solution will work for you?

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Jul 27, 2011 at 8:07 AM

Hi Noel

Thanks for your reply. I got it to work - I'll post the code and config below if anyone else should need it. Notice - I called my category PerfMonTest - most other examples use PlolycyInjectionas the category name.

using System;
using System.Configuration;
using System.Threading;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            IUnityContainer container = new UnityContainer();
            section.Configure(container);
            
            var ur = container.Resolve<IUserRepository>();
            ur.Create(new User());
          
            Console.WriteLine("Done.");
            Console.ReadLine();
        }

    }

    public interface IUserRepository
    {
        void Create(User obj);
        void CreateThrow(User obj);
    }

    public class UserRepository : IUserRepository
    {        
        public void Create(User obj)
        {
            Thread.Sleep(1);
        }

        public void CreateThrow(User obj)
        {
            Thread.Sleep(1);
            throw new Exception();
        } 
    }

    public class User
    {

    }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
  </configSections>    
  
 <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
   <assembly name="ConsoleTest"/>
   <namespace name="ConsoleTest"/>

   <sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension,                       
                      Microsoft.Practices.Unity.Interception.Configuration" />

   <container>
     <extension type="Interception" />

     <register type="IUserRepository" mapTo="UserRepository">
       <interceptor type="InterfaceInterceptor" />
       <policyInjection />
     </register>

     <interception>

       <policy name="policyTest">

         <matchingRule type="NamespaceMatchingRule" name="Namespace Matching Rule">
           <constructor>
             <param name="namespaceName" value="ConsoleTest" />
           </constructor>
         </matchingRule>

         <callHandler type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.PerformanceCounterCallHandler,
                       Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=5.0.414.0" name="perf counter handler">
           <constructor>
             <param name="category" value="PerfMonTest" />             
             <param name="instanceName" value="ConsoleTest" />
             <param name="useTotalCounter" value="true" />
             <param name="incrementNumberOfCalls" value="true" />
             <param name="incrementCallsPerSecond" value="true" />
             <param name="incrementAverageCallDuration" value="true" />
             <param name="incrementTotalExceptions" value="true" />
             <param name="incrementExceptionsPerSecond" value="true" />
           </constructor>
         </callHandler>

       </policy>

     </interception>

   </container>

 </unity>

</configuration>

Dec 1, 2011 at 1:46 AM

Hello Sir JAXN. I tried your code and doesn't return any error. but I couldn't add to view the performance counter and see the graph. I installed the performace counter like this:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Configuration.Install;
using System.Linq;
using System.Management;
using System.Reflection;
using System.Threading;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers;
using EntLib = Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Installers;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using Microsoft.Practices.Unity.InterceptionExtension;
namespace Instrumentation.Example
{
    class Program
    {
        static void Main(string[] args)
        {
        
            Console.WriteLine("Instrumentation");

   

            EntLib.PerformanceCountersInstaller installer =
                new EntLib.PerformanceCountersInstaller("TestCategory");

            IDictionary state = new System.Collections.Hashtable();
            installer.Context = new InstallContext();
            installer.Install(state);
            installer.Commit(state);
        
            Console.ReadLine();
        }
    }
    
}

I'm using EntLib 5.0 for research.
I follow this page http://msdn.microsoft.com/en-us/library/ff660892(v=pandp.20).aspx but there's something missing with the documentation?
Thank you for the reply. I'm sick with this problem. T_T

Dec 1, 2011 at 3:21 AM

Are you saying that the performance counters did not created?  You will need write access to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
so I would run your Console application as administrator to ensure that they get created.

 

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Dec 1, 2011 at 4:54 AM
randylevy wrote:

Are you saying that the performance counters did not created?  You will need write access to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
so I would run your Console application as administrator to ensure that they get created.

 

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Thank you for the response Sir. Creating performance counter is working but the problem, when I will select and add my performance counter(using the plus icon), I couldn't monitor it. I couldn't see it on the list of counters.

Dec 1, 2011 at 10:49 AM

So in Perfmon, when you go to add the category you don't see it in the list of counters?  You don't see "TestCategory" in the list of categories?

The code itself looks OK.  When I run it as administrator the counter is created.  If I run it as a standard user then I get an exception.

I'm assuming that you opened perfmon after you ran the installer so that the latest list of counters was loaded.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Dec 2, 2011 at 1:16 AM
Edited Dec 2, 2011 at 1:18 AM
randylevy wrote:

So in Perfmon, when you go to add the category you don't see it in the list of counters?  You don't see "TestCategory" in the list of categories?

The code itself looks OK.  When I run it as administrator the counter is created.  If I run it as a standard user then I get an exception.

I'm assuming that you opened perfmon after you ran the installer so that the latest list of counters was loaded.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Good day Sir.

The "TestCategory" is already installed in the application.

https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/392611_2222099795033_1323859513_31966932_1862475259_n.jpg

But when I want to monitor the performance counter, I couldn't see it here:

https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/384477_2222121195568_1323859513_31966936_137466898_n.jpg

Dec 2, 2011 at 2:57 AM
Edited Dec 3, 2011 at 4:16 AM

Hi,

It appears the issue, based on the images you posted (a picture is worth a thousand words!), is that there are no instance counters so there is nothing to monitor so the counters don't get added to the UI.

Try running your application and see if you see any instance counters.  If not, then that makes me think that the call handler is not being invoked.  Can you verify the 
handler is being invoked?  Perhaps start a new discussion and post your code and configuration.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Dec 2, 2011 at 4:09 AM
randylevy wrote:

Hi,

It appears the issue, based on the images you posted (a picture is worth a thousand words!), is that there are no instance counters so there is nothing to monitor so the counters don't get added to the UI.

Try running your application and see if the you see any instance counters.  If not, then that makes me think that the call handler is not being invoked.  Can you verify the 
handler is being invoked?  Perhaps start a new discussion and post your code and configuration.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com<

Hello Sir. Thank you for the response. I do not know what happened but it's working now. :)

Dec 2, 2011 at 4:35 AM

>I do not know what happened but it's working now. :)

It must be because I am all powerful.  ;)

Good to hear that it's working.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Dec 2, 2011 at 4:45 AM

Hahah! Thank you Sir.