ringchenhao commented on issue #263:
URL: 
https://github.com/apache/logging-log4net/issues/263#issuecomment-3082612491

   using log4net;
   using log4net.Config;
   
   [assembly: XmlConfigurator(Watch = true)]
   
   
   namespace Log4NetExample
   {
       internal class Program
       {
           // 获取 logger 实例
           private static readonly ILog log = 
LogManager.GetLogger(typeof(Program));
   
           static void Main(string[] args)
           {
               // 1.2  加载配置
               //XmlConfigurator.Configure(new 
FileInfo("ConsoleApp7.dll.config"));
   
               // 3. 使用日志记录
               log.Info("程序启动");
               log.Debug("这是一条 Debug 消息");
               log.Info("这是一条 Info 消息");
               log.Warn("这是一条 Warn 消息");
               log.Error("这是一条 Error 消息");
               log.Fatal("这是一条 Fatal 消息");
   
               // 模拟一个错误
               try
               {
                   int result = 1; // 模拟除以零的错误
               }
               catch (Exception ex)
               {
                   log.Error("发生异常", ex);
               }
   
               log.Info("程序结束");
   
               Console.WriteLine("日志已生成, 请检查 Logs 文件夹。按任意键退出...")            
Console.ReadKey();
           }
       }
   }
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to