c# Best Method to create a log file

前端 未结 12 552
甜味超标
甜味超标 2020-12-28 13:37

I\'m writing a tool that\'s going to be check the health of workstations across a network, and will fix according to the issues it finds. I want to create a log file as the

12条回答
  •  孤城傲影
    2020-12-28 13:53

    You could use the Apache log4net library:

    using System;
    using log4net;
    using log4net.Config;
    
    
    public class MyApp
    {
        // Define a static logger variable so that it references the
        // Logger instance named "MyApp".
        private static readonly ILog log = LogManager.GetLogger(typeof(MyApp));
        static void Main(string[] args)
        {
            XmlConfigurator.Configure(new System.IO.FileInfo(@"..\..\resources\log4net.config"));
            log.Info("Entering application.");
            Console.WriteLine("starting.........");
            log.Info("Entering application.");
            log.Error("Exiting application.");
            Console.WriteLine("starting.........");
        }
    }
    

提交回复
热议问题