Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 54713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:15:47+00:00 2026-05-10T17:15:47+00:00

In my webapplication (C#, .Net 3.5), made up of a core class library (containing

  • 0

In my webapplication (C#, .Net 3.5), made up of a core class library (containing the business logic, data layer and a couple of utility classes), a windows service project, a webservice project and the website project, I have a couple of static classes in the core library used by all other projects. These classes (for example the Log class) require some initialization (They have an Initialize method) in order to set them up for usage. As an example, the Initialize method of the Log class has a directory path parameter which tells the Log, where to save the logfiles to. Alternativly I was thinking of loading the ‘settings’ for the Log class from a configuration file in the static constructor. The drawback is, that I need different settings for unit-testing then in production code.

Is there a better way to design this? The drawback of this approach is, that all consumers of the static class will attempt to call Initialize. This is not really a problem because once initialized, the method will return immediately instead of executing the Initialize code again, but the design seems a bit weird to me.

I hope my english is sufficient to explain what I’m after. Do not hesitate to ask if the question is not clear enough.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:15:48+00:00Added an answer on May 10, 2026 at 5:15 pm

    I would try to avoid static classes for things which will require initialization. Make your Log class a normal class, and perhaps have a separate factory class to create instances or a single instance. You might want to use dependency injection to avoid having any statics, although this could get painful for something like logging which is pretty universal though.

    For logging in particular, both log4net and log4j (any reason you’ve rolled your own, btw?) use the idiom of asking some factory class for log instances based on names (commonly based on the name of the type using it). This is often stored in a static variable in each class which needs to perform logging. If the logging objects which are returned can still be affected by initialization of the logging subsystem afterwards, you don’t end up with ordering concerns where the DI container has to initialize the logging framework before the logging clients are initialized etc.

    Using separate logging objects instead of a static class improves testability – you can replace the logging object during a test with one which records the logs to ensure that (say) auditing information is captured. One downside of the logging objects being known statically is that this reduces the possibilities of running tests in parallel.

    Apologies for the somewhat random musings – I haven’t had my first coffee yet. Hopefully it’s helpful though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 264k
  • Answers 264k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your second solution should certainly improve efficiency, but isn't (at… May 13, 2026 at 12:19 pm
  • Editorial Team
    Editorial Team added an answer Unfortunately you have no real choice. You must (you really… May 13, 2026 at 12:19 pm
  • Editorial Team
    Editorial Team added an answer Could you pull the functionality into internal methods and use… May 13, 2026 at 12:19 pm

Related Questions

I am trying to replicate the exact functionality of this dialogue in Visual Studio
I have a set of functions I want to be available to my web
I have a web application that uses a number of WCF Services. I deploy
I am working on web application .net 3.5,asp.net,C#. In that i need to provide

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.