AddCategory stored procedure always executes when logentry?

Topics: Logging Application Block
Feb 16, 2010 at 3:20 PM


Running sql profiler I ca see that everytime I submit a logentry the stored procedure AddCategory gets called:

exec AddCategory @categoryName=N'General',@logID=103.

Why is this, as my c# code is straight from the documentation, i.e.:


            LogEntry log = new LogEntry();
            log.EventId = 300;
            log.Message "test message";
            log.Severity = TraceEventType.Information;
            log.Priority = 5;

I only have one category source defined in my config called 'Genera'.

I have tried taking out the line


from the above code but still this AddCategory executes.

Any ideas would be greatly appreciated.



<font size="2">




Feb 16, 2010 at 3:27 PM

The thing is, categories are only being added to the Category table once you send a logentry to the database.  It doesn't scan your config and enumerate all categories you defined there and add them to the table. 


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc. 

Feb 16, 2010 at 3:30 PM

wow thanks for the ultra quick response.

Is the net result of this then that I always have to the addcategory sp firing when I log an entry as this seems a bit unnessasry?


Feb 16, 2010 at 3:35 PM

Yes, it is.  But it doesn't execute the whole sp logic as I think you already know because it checks first if the category already exists in the table.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc. 

Feb 16, 2010 at 3:38 PM

sure, it is just that I am using this logging block to log all entity updates and it just means twice as many db calls, one to log an entry and one to call addcategory sp. A bit unecessary  but really like the rest of this so a small price to pay I suppose.

Thanks for the prompt response.