简体   繁体   中英

Which .Net classes will be the best to use for creating a logger for .Net Application

I have to create a logger for .net Application(I cant use third party framework).The requirements of the logger are :

  1. Logger should be configurable from .config file without stopping the application. It should have different levels for logging.

  2. Destination of log should be Console and Text file (Configurable )

  3. Logger should have ability to create another log file if max file size limits reached and should stop logging if there are not much space in disk.

  4. Logger should work in normal and throttling mode. Its should stop logging when there are continuous error because of some reason (say server is not up).

Please guide me which .net classes will be the best to use for creating a logger?

To answer your question, you can use the System.Diagnostics.Trace class to output messages in your application. You can configure it with TraceListeners that can output to a console, file or other data sources.

However, I would highly recommend speaking with your client, and explaining him that well-tested, free and open source solutions exist (libraries such as log4net and NLog), and reinventing the wheel might not be in his best interest.

Have a look at the System.Diagnostics namespace and especially the Trace class there:

http://msdn.microsoft.com/en-us/library/system.diagnostics.trace.aspx

The following namespaces will help you: System.Diagnostics and System.Reflection

Here are a couple implementations that you could use as a start:

http://www.codeproject.com/Articles/21338/AC-Central-Logging-Mechanism-using-the-Observer-a

http://www.codeproject.com/Articles/3953/Logger-in-C-An-easy-way-for-monitoring-NET-applica

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM