File Logger in C #

I am looking for a .net class to work with logging various information to a file. The registrar must have timestamps, categories for recorded data (to distinguish between reliability and errors), error severity levels, in order to be able to split the log file after it exceeds a certain size.

+4
source share
8 answers

Corporate library Block application block.

+9
source

I suggest using open source log4net

+11
source
+5

, . CommonLogging ( , , , Spring.Net), , , . .Net CommonLogging :

  • System.Trace
  • Log4Net
  • NLog
  • MS Enterprise
  • ConsoleOut

.

+4

, .NET, EventLog ( System.Diagnostics), Windows.

:

using System.Diagnostics;


class LogSample{

   public static void Main()
   {
      // let create our application log file
      if (!EventLog.SourceExists("ApplicationLog"))
      {
         EventLog.CreateEventSource("ApplicationLog", "SampleLog");
      }

      EventLog log = new EventLog();
      log.Source = "ApplicationLog";

      // Here we can write the "categories" you require
      log.WriteEntry("Some error entry goes here", EventLogEntryType.Error);

      log.Close();

      // where EventLogEntryType enum has "Error", "Warning", "Information"
      // we are done with the event log ... forever (ie. we don't want it on the machine)
      log.Delete("ApplicationLog");
   }
}
+2

.net- . .

, , , , , .

( , zip )

+2

As the previous posters suggested, I would say take a look at Log4Net - it is similar to Log4J and allows a lot of functionality ...

I would suggest reading: http://logging.apache.org/log4net/release/faq.html

+1
source

Enterprise Library is open source and Microsoft.

0
source

All Articles