Unit Test / Config File / Logging Application Block

G

Guest

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)
 
L

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.)
 
G

Guest

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!
 
L

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top