Translate XML Config to Fluent Configuration API

Topics: Building and extending application blocks, Exception Handling Application Block, General discussion, Logging Application Block
Aug 10, 2010 at 7:34 PM

I have a need to use the Logging and Exception apps blocks in my app w/o the ability to use an App.Config file.  Is there an easy means to translate what the configuration utility generates into the fluent config API? Would be nice if the config util could output fluent api C# code as an option.  Thanks!

Aug 11, 2010 at 1:17 AM

There's currently no support for that.

 

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

Aug 11, 2010 at 2:44 PM

I know it can't however, nudge nudge, in a future version it could.

Aug 11, 2010 at 5:17 PM

There is some unclear issues with the fluent API. For example, where do I set the minimum TraceEventType level? In the app.config, that is the switchValue attribute on the add element under categorySources.

Aug 12, 2010 at 3:29 AM

Yeah, the converter from config to fluent API code is definitely a good enhancement for future releases. Actually, for what I know enhancement are welcome for future improvement on entlib releases, all you need to do is to logged this in the Issue Tracker.

As for the TraceEventType level filtering when using Fluent API, try adding something like this code .WithOptions.ToSourceLevels(System.Diagnostics.SourceLevels.Off) before defining your trace listener. The code may look something like this

 builder.ConfigureLogging()
                   .WithOptions
                     .DoNotRevertImpersonation()
                     .LogToCategoryNamed("Security")
                     .WithOptions.ToSourceLevels(System.Diagnostics.SourceLevels.Off)
                   .SendTo.FlatFile("Security Log File")
                       .FormatWith(new FormatterBuilder()
                         .TextFormatterNamed("Text Formatter")
                           .UsingTemplate("Timestamp: {timestamp}...{newline}\nMessage: {message})}"))
                           .ToFile("security.log")

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

Aug 12, 2010 at 6:13 AM
If there's something in the fluent interface you don't like or find confusing, please let us know! We were begging for feedback on it during development and got none, so we basically said "we have what we have, let's wait for the community to let us know if we got it right." Right now we have no idea because nobody's said anything.
Aug 12, 2010 at 2:58 PM

So, therefore I should be fine with this:

var builder = new ConfigurationSourceBuilder();
builder.ConfigureInstrumentation().EnableLogging();
builder.ConfigureLogging()
    .WithOptions
    .LogToCategoryNamed("General")
    .WithOptions
#if !DEBUG
    .ToSourceLevels(SourceLevels.Error)
#endif
    .SetAsDefaultCategory()
    .SendTo
    .FlatFile("Log File")
    .FormatWith(new FormatterBuilder()
    .TextFormatterNamed("Textformatter").UsingTemplate(LogTemplate))
    .ToFile(logFilePath);
However do I need to define each level I want, or will it log everything from Error and up? The idea here is that for DEBUG code, I want my TraceEventType.Verbose to hit the log, but when I push Release code, only want to see TraceEventType.Error and above.

 

Aug 12, 2010 at 4:10 PM

I put the request into the Issue Tracker.  Also, the docs for the fluent API are somewhat week.  I had to rely on Intellisense and the Object Browser as well as this CodeProject article http://www.codeproject.com/KB/aspnet/HttpModuleLoggingAppBlock.aspx

Aug 13, 2010 at 8:07 AM
Edited Aug 13, 2010 at 8:45 AM

You need not specify every level you want.  See the Configuring Trace Sources Special Category topic in the documentation for more info.

 

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

Aug 14, 2010 at 7:20 AM
bittondb wrote:

I put the request into the Issue Tracker.  Also, the docs for the fluent API are somewhat week.  I had to rely on Intellisense and the Object Browser as well as this CodeProject article http://www.codeproject.com/KB/aspnet/HttpModuleLoggingAppBlock.aspx

To be honest, the lack of documentation was deliberate. There were two reasons for this. First, we figured that if we got the API right, we shouldn't need documentation; the whole point was to have intellisense guide you to the settings you need. Obviously, we didn't get it perfect, but we tried. The second reason was, quite simply, resources. We only have 1.5 writers on the project, they were both swamped, and the fluent API would be potentially enormous with all the possible combinations. Add in that we were hoping intellisense would help things, we decided to scrimp on the docs in this area.

Aug 17, 2010 at 5:38 PM

For the right financial incentive, I'd be more than happy to expand on the documentation.

Aug 17, 2010 at 5:45 PM

If we'd had money to allocate to this documentation, we would have done it the first time. Nice try though. :-)