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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:02:03+00:00 2026-05-27T19:02:03+00:00

My program has a handful of classes, and 2 forms. My first form Main

  • 0

My program has a handful of classes, and 2 forms. My first form “Main” has a button that will show the second form “formSettings” and a button that will open a log file.

FormSettings formSettings = new FormSettings();
LogClass objectLog = new LogClass();

public void settingsToolStripMenuItem1_Click(object sender, EventArgs e)
    {
        //shows the settings form
        formSettings.Show();            
    }


private void viewLogToolStripMenuItem1_Click(object sender, EventArgs e)
    {            
        try
        {
            objectLog.OpenLogFile();
        }
        catch (Exception ee)
        {
            objectMessageBox.ReturnErrorOpeningLogPrompt(ee.ToString());
        }
    }

My Main form creates instances of both the Settings form as well as the Log class. My settings class also creates an instance of the Log object. The problem I have now is that the log class does some validating based on entries from the settings class, however I can’t call for an object of the settings class since it calls the log class or I end up with an infinite loop. Here’s the validation it does.

public void Write_Log_Data(string data)
    {
        //Create an outfile stream
        FileStream outfile = new FileStream(fileLocation,
            FileMode.Append, FileAccess.Write);
        StreamWriter writer = new StreamWriter(outfile);

        if (objectSettings.chbxLogScanResults.Checked == true)
        {
            if (data == null || data == "")
            {
                //this is for logging ip addresses
                writer.WriteLine(Properties.Settings.Default.IPAddressNew + CONST_TAB +
                    GetDateTime());

            }
            //because logs containing errors or changed ips are not null data they trigger this section
            else
            {
                //the error was already formatted so just write it
                writer.WriteLine(data);
            }

            //close our writers
            writer.Close();
            outfile.Close();
        }
    }

What I’m wondering is should the log file be static? Can it be static? I want to be able to call a LogOpen() method that is part of the LogClass from either form, but as shown above there is some checking that occurs based on entries of one of the forms that calls the log class. What might be a good solution to try for this if I can’t use the log file as a static class (I don’t understand static classes very well hence my asking).

  • 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-27T19:02:04+00:00Added an answer on May 27, 2026 at 7:02 pm

    Yes, LogClass can absolutely be static and, in fact, if it is accessed from multiple locations, it is probably better that it is.

    However, you will need to change how the form settings are communicated to the log class. You will either need to add static properties to the log class to store the values from the forms or you will need to pass the values from the forms to the methods in the log class.

    For example, if your user clears the chbxLogScanResults in your settings form, then you can either update the LogClass with this information immediately or when the settings form is saved (I prefer to do this on save so that if the user cancels the changes to the form, you don’t record preferences incorrectly).

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

Sidebar

Related Questions

My program has a splitcontainer within the form. Panel1 has a button that when
My program has two threads: Main execution thread that handles user input and queues
My program has a handful of settings that need to be established before it
My program has a main thread that takes command input from a user. Separately,
My program has to read files that use various encodings. They may be ANSI,
I have an application that seems to throw exceptions only after the program has
My program has been working perfectly so far, but it turns out that I've
My program has a list of tabs that each contain a list of people.
My program has one button, and the other one is a JTextField. The action
My program has a component - dubbed the Scheduler - that lets other components

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.