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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:46:12+00:00 2026-05-31T08:46:12+00:00

I built an application and want to use logging in my application before giving

  • 0

I built an application and want to use logging in my application before giving it out to a user to know the actions the user did in case before any error.
I haven’t used logging before, so I did a bit of study to find out good methods for the same and perhaps Trace class in .NET looks like what might help in this scenario.
Using a text file seems to be a better idea here for the logging setting a TextWriterTraceListener in the App.Config file of my project, and using in the code Trace.Writeline("Error info", "Field");

1) Even after reading good amount of content, I am not sure about good approaches for logging?
Should there be different error logger and information logging files?
How does logging work for specifying different types of error (such as warning, critical, error etc.?)

2) I want to use the same logfile in one of my other projects in the solution. So, do I add the same Trace Listener section in the App.Config of my project?

  • 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-31T08:46:14+00:00Added an answer on May 31, 2026 at 8:46 am

    With a logging library (such as log4net), you can do all the things you are asking about easily. You can set up your logging in a config file to go to event log, file, console, etc (or any combination) and set the logging levels independently.

    That is, you can say the file will have informationals, warnings, errors, and fatals, but the event log will log only the errors and fatals.

    In general, nearly all of the logging libraries have these features. The examples below are just in terms of log4net but the same concepts apply to most logging libraries…

    To get the logger in any class in your solution, you just need to ask for a logger in your class:

    public MyClass
    {
        private static readonly ILog _log = log4net.LogManager.GetLogger(typeof(MyClass));
    
        public void SomeMethod()
        {
            _log.Debug("This is a debug message.");
            _log.Info("This is an informational message.");
            _log.Warn("This is a warning message.");
            _log.Error("This is an error message.");
            _log.Fatal("This is a fatal message.");
        }
    }
    

    In addition, you can filter based on the loggers, that is, you could suppress log messages from paraticular classes or only display logging messages for a subset of classes, etc.

    A sample config settings block would look like this. This creates a rolling file appender (keeps several days worth of logs) and Console appender

    <log4net>
        <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
            <file value="c:\logs\AgentLog"/>
            <appendToFile value="true"/>
            <datePattern value=".yyyy-MM-dd"/>
            <rollingStyle value="Date"/>
            <MaxSizeRollBackups value="14"/>
            <param name="StaticLogFileName" value="false"/>
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%d{HH:mm:ss.fff} [%thread] %-5level %logger{1} - %m%n"/>
            </layout>
        </appender>
        <appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
            <mapping>
                <level value="FATAL"/>
                <foreColor value="Yellow"/>
                <backColor value="Red, HighIntensity"/>
            </mapping>
            <mapping>
                <level value="ERROR"/>
                <foreColor value="Red, HighIntensity"/>
            </mapping>
            <mapping>
                <level value="WARN"/>
                <foreColor value="Yellow, HighIntensity"/>
            </mapping>
            <mapping>
                <level value="INFO"/>
                <foreColor value="Green, HighIntensity"/>
            </mapping>
            <mapping>
                <level value="DEBUG"/>
                <foreColor value="White"/>
            </mapping>
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%d{HH:mm:ss.fff} [%thread] %-5level %logger{1} - %m%n"/>
            </layout>
        </appender>
        <root>
            <level value="INFO"/>
            <appender-ref ref="RollingFileAppender"/>
            <appender-ref ref="ColoredConsoleAppender"/>
        </root>
    </log4net>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built an application that I want to use as the foundation for
I have an already built application and I want to add a feature that
I have built an application that uses SQL Express 2005 and I want to
I already have an application built in asp.net 3.5 and now I want to
I'm working on an html5 application built on CouchDB. I want to make sure
i just join phonegap, i want a built test application. i write some code
We have an application that we have built as a bundle and we want
I want to build an application that exports user data of another app. The
We have built an application using wxWidgets in C++ and use wxToolTips to provide
I am trying configure a Django application to use mysql. I want to use

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.