C # Logging. What should i use?

I am considering moving to a new unified logging solution for use in our new product line, and I wanted to see what some of the Stack Overflow people thought. We will need logging for various applications: ASP.net, Windows services, web services, wpf applications, etc. We are only in the Windows store.

Some of our requirements for a registration solution:

1) Manage log files

- Ability to split files up over a certain size - Ability to auto archive/delete after certain period of time 

2) The ability to send e-mail to certain types of registered messages (for example, errors)

3) The ability to write messages to the Windows event log

 - We need to be able to specify where it being written in the event log. It would also be nice if it would automatically create the event log source if it does exist. 

I started looking for nLog, window tracing and log4net. I am not limited to these 3, these are just some of them that come in search of.

+27
c # windows logging
Jan 12 2018-11-12T00:
source share
7 answers

log4net is always a good choice.

http://logging.apache.org/log4net/

+17
Jan 12 2018-11-12T00:
source share

Use the .NET general log . You can later select a specific provider (NLog, CLog, log4net ...) or even create your own.

+11
Jan 12 '11 at 16:11
source share

And one more: NLog .

  • Files - one or several files, with automatic file naming and archiving.
  • Event Log - Local or Remote Database - Store your logs in supported databases.
  • from the .NET Network - using TCP, UDP, SOAP, MSMQ
  • Command line console - including color-coded message
  • Email - you can receive emails when application errors occur
  • ASP.NET trace
  • and much more
+9
Jan 12 '11 at 16:10
source share

You can take a look at the corporate library, they have a block of logging applications that is extensible

http://entlib.codeplex.com/

http://entlib.codeplex.com/releases/view/46741

you can download the pdf developer guide, they have a registration section (chapter 4)

+3
Jan 12 2018-11-12T00:
source share

See this question for another comprehensive answer: When should I use Tracing vs Logger.NET, Enterprise Library, log4net or Ukadc.Diagnostics?

In short, the main available base logging systems are the built-in .NET Framework System.Diagnostics, log4net, NLog, and Enterprise Library application block.

A comparison of these basic structures is available at: https://essentialdiagnostics.codeplex.com/wikipage?title=Comparison

1) Manage log files

All of the basic structures listed above support sliding files, but I think they leave you clean.

eg. in the past, I used a Windows scheduled task that uses robocopy with "/ mov / minage X" to move old files to another location, then delete or something else.

The EventSchemaTraceListener function used by System.Diagnostics, which I recently posted on the blog , has the LimitedCircularFiles parameter, but there is not much support for the log viewer tool (they are in XML).

2) The ability to send e-mail to certain types of registered messages (for example, errors)

All the main structures listed above support this either directly or through extensions (additional listeners).

3) The ability to write messages to the Windows event log

Again, all major frameworks support this, but I usually recommend that writing to the Windows event log is done directly, not through tracing.

One of the problems is what you asked about to automatically create sources.

Any entry in the event log (which passes through EventLog.WriteEvent) will automatically try to create a source in the first message of the log, if it does not exist - the problem is security, only administrators can create sources, so it does not work as a regular user.

Because of this, you really need to add an EventLogInstaller so that the source is created during installation (installation is done by the administrator). After creation, any process can then write to the source.

This leads to my recommendation that you need to create and write code in the event log to ensure that the source of the event log is the same. In addition, if you write to the event log, you do not want it to "disable it" through the wrong configuration.

My personal recommendation is for the .NET Framework System.Diagnostics utility, in particular the Service Trace Viewer is great for diagnosing problems, especially in multi-level multi-threaded environments, if WCF is used, where it can be correlated, identifies different levels.

+1
Apr 21 '13 at 8:09
source share

You can create your own logbook ... I did.

Take a look at PostSharp http://www.sharpcrafters.com/ , they have very good examples of some basic logging systems.

0
Jan 12 '11 at 16:32
source share

http://alexworx.imtqy.com/ALox-Logging-Library/

is a fairly simple library that is great if you have high performance requirements.

0
Jun 20 '13 at 14:06 on
source share



All Articles