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 6777069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:06:14+00:00 2026-05-26T16:06:14+00:00

First: Excuse me if the question is wrong, I don’t really know how to

  • 0

First: Excuse me if the question is wrong, I don’t really know how to describe it since I’m not a pro on coding terms.

So I have written this line in the main class:

    public Log log = new Log("program.log");

Which starts a session of my logger. I then use that session to write to the log everywhere in my main class code.
But I am doing the dirty work in another class, so I want to log there too. How do I access the same “log session” from that class?

Writing MainClassName.log doesn’t work.

  • 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-05-26T16:06:15+00:00Added an answer on May 26, 2026 at 4:06 pm

    No, MainClassName.log won’t work because your variable is an instance variable. It would need to be a static variable… or you’d have to have an instance of MainClassName through which to access the instance variable.

    However, personally I’d advise you not to use public variables at all. I would suggest using private variables for everything other than “constants” (where that can be a readonly variable of an immutable type, not just something that .NET considers a constant) – and even then in many cases.

    I would also suggest the use of something like log4net – and you’re likely to benefit from using a separate logging object per class, so that you can easily switch logs from different classes on or off (or use even more fine-grained control with severities).

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

Sidebar

Related Questions

Please excuse me for a probably low quality of this question, since I'm not
My first ever question here. Please excuse me, I have just entered into C++
First of all, excuse my poor topic title. I simply have no idea how
First of all, I know how to build a Java application. But I have
First let me say that I really feel directionless on this question. I am
this is the first question I post in this site, so you have to
First of all, please excuse any typo, English is not my native language. Here's
First of all, please excuse any typo as English is not my native language.
Excuse the long question! We have two database tables, e.g. Car and Wheel. They
This is my first question, so please excuse me for any mistake I make.

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.