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

  • SEARCH
  • Home
  • 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 7829779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:54:36+00:00 2026-06-02T10:54:36+00:00

I am writing a singleton logger with logging level for my exe and dll.

  • 0

I am writing a singleton logger with logging level for my exe and dll.

The Logger.h:

#define LOG CLogger::GetInstance().Log
#define LOG_PATH _T(".\\LogFile\\Logger.log")
enum eLogLevel { NONE=0, ERR, WARNING, USER, SYSTEM, DEVELOPER };  

class CLogger  
{
public:
    //Construcor & Destructor
                    CLogger();
    virtual             ~CLogger();
    //Singleton 
    static CLogger&     GetInstance();          
    //For logging level preference
    //Example: WARNING -> Log only ERR & WARNING messages
    //Default = NONE
    virtual void        SetLogLevel(eLogLevel eLevel);  
    //Logging
    virtual void        Log(eLogLevel eLevelType, CString szText);  

protected:
    //Open & Close the log after used
    virtual void        CloseLog();
    virtual BOOL        OpenLog();

    CStdioFile      m_File;
    CString         m_szFile;
    eLogLevel       m_eLevel;
    BOOL            m_bFileOpened;
};

The idea is, EXE project will need to include Logger.cpp & Logger.h, responsible to set the logging level.

Meanwhile, DLL project will need to include Logger.cpp & Logger.h, but no need to set the logging level, as it will follow the logging level of EXE project.

Both of EXE & DLL are expected to able to write anything into the same log file.

The outcome now is, I will need to ask DLL project to SetLogLevel() so that DLL project is able to write into log file.

Can anyone spot the problem on the Logger.h above? Wouldn’t the Singleton sharing one instance of object including member variables, as EXE & DLL will be running on the same process/thread?

  • 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. Editorial Team
    Editorial Team
    2026-06-02T10:54:38+00:00Added an answer on June 2, 2026 at 10:54 am

    For a singleton object in this case, it will be instantiated twice in EXE and DLL.

    Both of them are created in different memory address, hence, they are sharing different member variable. It indicates both of them exist without knowing each other.

    Now, there are probably two ways to solve this problem:
    1) instantiate the only ONE logger by wrapping the Logger class into DLL
    2) EXE and DLL create instance separately, they need to set the log level at EXE and DLL

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

Sidebar

Related Questions

I'm writing a class for logging events. My LogClass is implemented as a singleton,
I'm writing a factory class that should be able to return singleton instances of
Writing a .NET DLL how do I find Application.ProductName ? EDIT: Obviously, importing Windows.Forms
Once the singleton pattern is understood, writing subsequent singleton classes in C# is a
Is there any way to avoid writing data to the singleton ModelLocator in Cairngorm?
I'm writing a network app, where each Client has a Singleton ClientManager. For testing
The classic of writing a singleton in java is like this: public class SingletonObject
I am writing a .NET Remoting application. I have my dll, server, and client
I'm writing a Singleton class in Java EE 6 using the @Singleton annotation. I
I am writing an iPhone app and I want to create a NSCache singleton.

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.