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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:01:34+00:00 2026-05-27T23:01:34+00:00

I have a log tool for my applications. I log to XML in a

  • 0

I have a log tool for my applications. I log to XML in a hierarchical manner (this means that I can nest log items). My Log(string, bool) takes two parameters, one with the string to log and a bool value determining if this comment should be nested below the previous log comment. A PopLog() method is made to go to the parent, and continue logging on the parent level.

This means that when I log like this:

Log("first", false);
...
Log("Second", true);
...
Log("Third", true);
PopLog();
PopLog();
PopLog();

This gives the following result:

<first>
  <second>
    <third>
  </second>
</first>

The problem I have with the current design is it is hard to keep track of my log level, how deep I am in the logging tree, and whether or not I need to pop, log using true, or log using false.

Any good ideas on how to make this simpler, more maintainable and better (changing log provider is not an option)?

  • 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-27T23:01:35+00:00Added an answer on May 27, 2026 at 11:01 pm

    A better design would be, IMO, to separate the push/pop behaviour from the logging itself. Here’s a solution in C#, using IDisposable:

     class IndentedLog : IDisposable
     {
        public IndentedLog() 
        {
           Log.IndentLevel++; 
        }
        public void Dispose() 
        {
           Log.IndentLevel--;
        }
     }
    

    This way, you can do something like:

         Log("first");
         // ...
         using (new IndentedLog())
         {
             Log("second");
             // ...
             using (new IndentedLog()) 
             {
                Log("third");
             }
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a tool to collect log files within a time window specified
We've faced strange problem. We have log on service, that authenticates user, adds auth
I have several log files of events (one event per line). The logs can
i have a log file which contains hundreds/thousands of seperate XML messages and need
I have a log that is really huge. (millions of rows) LogTable ------- ID
I have a log file in SqlServer that stores the time an application started,
I have a log function on my admin panel that checks user input for
We have this strange bug report from a customer: Log file last modification date
Can anyone recommend a tool (ideally FOSS) that can analyse an .NET assembly and
I have a Sql Server db that was generated by Nhibernate's schema tool and

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.