Using the Fluent Configuration API with Logging Application Block

Topics: Logging Application Block
Feb 21, 2011 at 1:39 PM

Ent.Lib's fluent configuration is really very nice.great job!. I tried to configure LAB to log every thing on database.  so i started to write these lines

var builder = new ConfigurationSourceBuilder();

builder.ConfigureLogging().SpecialSources.LoggingErrorsAndWarningsCategory.SendTo.????
actually i am waiting something like SendTo.Database().. etc. but i couldnt find it. Could you please provide me a sample code which logs to database with fluent API.
Feb 21, 2011 at 9:23 PM

@olcay

Thanks for your feedback. As to your question, SendTo.Database().. is already there. Just make sure to add reference to Microsoft.Practices.EnterpriseLibrary.Logging.Database.

Grigori 


Grigori Melnik
Enterprise Library Producer
Senior Program Manager
Microsoft patterns & practices
http://blogs.msdn.com/agile
@gmelnik

Feb 22, 2011 at 10:36 AM

thanks for reply. I configured LAB as,

var builder = new ConfigurationSourceBuilder();

builder.ConfigureLogging().SpecialSources.LoggingErrorsAndWarningsCategory.SendTo.Database("db") .UseDatabase(".").WithAddCategoryStoredProcedure("sp_log");

i see that logging to db is only possible with procedures. is it possible to write custom insert command. someting like;

.UseDatabase(".").WithAddCategoryCommand("insert into logtable values(@p1,@p2,@p3..)").;

Feb 23, 2011 at 2:06 AM

It isn't possible without creating your own extension for it and a custom database trace listener which you can use with that extension.  You can check the SendToDatabaseListenerExtensions static class where you can find the SendToDatabaseTraceListenerBuilder private class from the EntLib source code to see how it does that for the built-in database trace listener.

 

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