Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm writing a class library as an abstraction to use for logging in any application, service, etc. that I write. I'm making it decently robust by making it very configurable to suit my needs for most application/service logging scenarios that I come across.

The config is designed to specify things such as:

  • What logging level to write
  • Write to one log file for all levels
  • Write to separate files per level
  • Logging cutoff (periodic, app event, byte size restricted)
  • Log file expiration (delete log files after file age)
  • Write as flat text or XML
  • Log file name format specification
  • Whether to prefix filename with date
  • Parent app's name
  • etc, etc, etc...

I've read some other stackoverflow questions regarding configs for DLL assemblies and it causing conflict between the app.config for the hosting assembly/app. I believe that my assembly has just cause to provide a config file.

Is this a good scenario for that occasion? Is it perhaps a better idea to bake my own config into my project so that my logger reads from XML files to retrieve config values?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
105 views
Welcome To Ask or Share your Answers For Others

1 Answer

What you could do is

  • create a custom configuration section (using e.g. the COnfiguration Section Designer tool)

  • put your assembly's configuration into a separate MyAssembly.config file

  • reference that assembly config file from your host app's config:

    <configuration>
       <configSections>
           <section name="YourAssembly" 
                    type="YourAssembly.ConfigSection, YourAssembly" />
       </configSections>
    
       <YourAssembly configSource="MyAssembly.config" />
    </configuration>
    

That way, you can "externalize" your configuration into a separate config file which you have only once (in your assembly's project), and any project needing it just needs those settings in its own config file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...