Home All Groups Group Topic Archive Search About

Unit Test / Config File / Logging Application Block

Author
26 Apr 2006 11:28 AM
Dick
I'm trying to write some unit tests to prove that I understand how the
Logging Application Block works. I trying to write a test that updates the
config and then writes a log. But this is failing with the message "The
configuration section for Logging cannot be found in the configuration
source." which (I guess) indicates that the Logging Application Block isn't
seeing my config changes. Can you tell me why and/or how to make it work.
Thanks.

Here's my code:

Imports S = System.Configuration
Imports L = Microsoft.Practices.EnterpriseLibrary.Logging

Dim _Configuration As S.Configuration = _
   S.ConfigurationManager.OpenExeConfiguration(S.ConfigurationUserLevel.None)

Dim _LoggingConfiguration As New L.Configuration.LoggingSettings
_Configuration.Sections.Add("loggingConfiguration", _LoggingConfiguration)
_Configuration.Save()

Dim _LogEntry As New L.LogEntry
L.Logger.Write(_LogEntry)

Author
27 Apr 2006 5:20 AM
Luke Zhang [MSFT]
Hello,

To use the Logging Application block, you need a "<loggingConfiguration>"
in app.config file, for example:

<configSections>
        <section name="loggingConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSet
tings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=null" />
    </configSections>
    <loggingConfiguration......

To generate this section, you can use the enteprise library configration
tool:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html
/entlib.asp

Hope this help,

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Author
27 Apr 2006 6:28 AM
Dick
Sure, I understand that - the code (in my original post) programmatically
adds the necessary "<loggingConfiguration>" to app.config. But it appears
that the Logging Application Block doesn't see my changes – hence my post.
Interestingly, if I start with an app.config containing the minimum
"<loggingConfiguration>" then I can programmatically make changes to it and
the Logging Application Block does see them!

Show quote
"Luke Zhang [MSFT]" wrote:

> Hello,
>
> To use the Logging Application block, you need a "<loggingConfiguration>"
> in app.config file, for example:
>
> <configSections>
>         <section name="loggingConfiguration"
> type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSet
> tings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0,
> Culture=neutral, PublicKeyToken=null" />
>     </configSections>
>     <loggingConfiguration......
>
> To generate this section, you can use the enteprise library configration
> tool:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html
> /entlib.asp
>
> Hope this help,
>
> Luke Zhang
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>
Author
28 Apr 2006 5:19 AM
Luke Zhang [MSFT]
If you programmatically adds the "<loggingConfiguration>" section in
app.config, it won't take efrfects until the application gets restarted.

Regards,

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

AddThis Social Bookmark Button