IsEnabled in SLAB is returning always false

Topics: Semantic Logging Application Block
Aug 28 at 8:21 PM
Edited Aug 28 at 8:22 PM
Hello,

I am new to SLAB and having an issue.

My write event is not firing because the "IsEnabled" is always false. Here is my code snippet.

Listener
private static ObservableEventListener consoleListenerAll = new ObservableEventListener();

consoleListenerAll.EnableEvents(LoggerEventSource.Log, EventLevel.LogAlways, Keywords.All);
consoleListenerAll.LogToFlatFile("C:\Test\Test.log");

Keywords
   public static class Keywords
   {
        public const EventKeywords AppStart = (EventKeywords)1L;
        public const EventKeywords PageStart = (EventKeywords)2L;
        public const EventKeywords Info = (EventKeywords)4L;
        public const EventKeywords Warn = (EventKeywords)8L;
        public const EventKeywords Debug = (EventKeywords)16L;
        public const EventKeywords Failure = (EventKeywords)32L;
   }
My Event

public class LoggerEventSource:EventSource
{
       [Event(100, Message = "Application Starting up.",Keywords= Keywords.AppStart, Level =               
                                                                                                                 EventLevel.Informational)]
    public void StartUp()
    {
        if (this.IsEnabled(EventLevel.Informational, Keywords.AppStart))
        {
            this.WriteEvent(100);
        }
    }
}

Any help is highly appreciated.

Thanks,


Note : I never got this to work.
using (var listener = RollingFlatFileLog.CreateListener("C:\Test\Test",1024,"MMDDYYYY",RollFileExistsBehavior.Overwrite,RollInterval.Minute))
{
        listener.EnableEvents(LoggerEventSource.Log, EventLevel.LogAlways, Keywords.All);
}
Editor
Aug 29 at 5:31 AM
The following console application based on your posted code works fine:
using Microsoft.Practices.EnterpriseLibrary.SemanticLogging;
using System.Diagnostics.Tracing;

namespace SLAB_Test
{
    public class LoggerEventSource : System.Diagnostics.Tracing.EventSource
    {
        public static LoggerEventSource Log = new LoggerEventSource();

        public static class Keywords
        {
            public const EventKeywords AppStart = (EventKeywords)1L;
            public const EventKeywords PageStart = (EventKeywords)2L;
            public const EventKeywords Info = (EventKeywords)4L;
            public const EventKeywords Warn = (EventKeywords)8L;
            public const EventKeywords Debug = (EventKeywords)16L;
            public const EventKeywords Failure = (EventKeywords)32L;
        }

        [Event(100, Message = "Application Starting up.", Keywords = Keywords.AppStart, Level = EventLevel.Informational)]
        public void StartUp()
        {
            if (this.IsEnabled(EventLevel.Informational, Keywords.AppStart))
            {
                this.WriteEvent(100);
            }
        }
    }

    class Program
    {
        private static ObservableEventListener consoleListenerAll = new ObservableEventListener();

        static void Main(string[] args)
        {
            consoleListenerAll.EnableEvents(LoggerEventSource.Log, EventLevel.LogAlways, Keywords.All);
            consoleListenerAll.LogToFlatFile(@"C:\test\Test.log");

            LoggerEventSource.Log.StartUp();
        }
    }
}

Take a look and see if there are any differences between your code and the above. If you can't solve the issue then post a complete sample that recreates the behavior.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Aug 29 at 2:47 PM
Hello Randy,

Thanks for your response. I really appreciate your response.
I started a console application and added this code and it worked. So then I started looking at my code and found out that I was not calling the Start Listener code explicitly. My bad.
I had the Start and Stop listener methods separately.

So I am good now. Thanks again for your help.

Thanks,
Siva.


Editor
Aug 29 at 3:31 PM
Good to hear!