using LogCallHandler attribute

Topics: Logging Application Block
Dec 9, 2010 at 3:46 PM

Hi,

    I have this class with a method called GetById, this method use LogCallHandler attribute.

 public class OrderComponent : Component, IOrderComponent
    {

        [LogCallHandler(Categories = new string[] { "General" }, AfterMessage = "Especialidad Select() Ejecutado", LogBeforeCall = false, LogAfterCall = true, Severity = System.Diagnostics.TraceEventType.Information)]
        public Order GetById(long id) {

            return new Order() { Id = 1000, Description = "Pruebas Descripcion" };
       
        }

 this class inherits from Component and Component inherits from MarshalByRefObject

public class Component : MarshalByRefObject {

Our problem is the aplication don't write in log file. 

 For the other hand, in manual way :

 LogWriter writer = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
            LogEntry log = new LogEntry();
            log.Categories.Add("General");
            log.Message = "Prueba";

            writer.Write(log);

it does correctly.

What can it be the problem?

 est regards

Dec 9, 2010 at 5:24 PM

my unity section in web.config file is:

.......

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">

        <assembly name="ConsoleApplication1"/>
        <assembly name="Microsoft.Practices.Unity"/>
        <namespace name="ConsoleApplication1"/>
 
        <!-- UNITY CONTAINERS -->
        <container name="RootContext">
            <register type="IOrderComponent" mapTo="OrderComponent">

            </register>
            <register type="Context"></register>
        </container>

    </unity>

Dec 10, 2010 at 6:33 AM

I'm unable to reproduce your scenario. I was able to successfully log using the snippet below. Though may still missing something in your whole app. Could you send us your sample repro project for this for us to investigate further. 

namespace PIAB.ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var oc = PolicyInjection.Create<OrderComponent>();
            Console.WriteLine(oc.GetById().ToString());
        }
    }

    public class OrderComponent : Component
    {       
        [LogCallHandler(Categories = new string[] { "General" }, AfterMessage = "Especialidad Select() Ejecutado", LogBeforeCall = false, LogAfterCall = true, Severity = System.Diagnostics.TraceEventType.Information )]
        public int GetById()
        {
            return 100;
        }
    }

    public class Component : MarshalByRefObject {}

    public interface IOrderComponent
    {
        int GetById();
    }


}

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Dec 10, 2010 at 8:03 AM

Hi Gino,

        the example which you send me it works perfectly. The problem is in the web application. I'm researching but don't detect the reason. I sent an email with attached code.

        Please, see you and tell me.

Best regards from Spain

 

 

Dec 13, 2010 at 10:53 AM

We'll look into this and post you for any updates.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Dec 13, 2010 at 2:33 PM

thank you in advance.

Dec 13, 2010 at 11:25 PM

Are you using a rolling flat file trace listener?  Is impersonation enabled in your web application?  If both are true, try setting the Revert Impersonation property of the Logging Settings to false.

 

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