wzp
2021-06-08 85e2382799b60c823e3613256605fdde928b0fd6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AutoCheckSMS.Common
{
    /// <summary>
    /// 日志服务
    /// </summary>
    public class Log4netService
    {
        static Log4netService()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "log4net.config";
            log4net.Config.XmlConfigurator.Configure(new FileInfo(path));
        }
 
 
        public static log4net.ILog GetLog(string logName)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(logName);
            return log;
        }
        private static string DefaultLoggerName = "RollingFileLog";
        private static string ErrLoggerName = "ErrRollingFileLog";
 
        public static void Debug(string message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(DefaultLoggerName);
            if (log.IsDebugEnabled)
            {
                Console.WriteLine($"{DateTime.Now}-{message}");
                log.Debug(message);
            }
            log = null;
        }
        public static void Info(string message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(DefaultLoggerName);
            if (log.IsInfoEnabled)
            {
                Console.WriteLine($"{DateTime.Now}-{message}");
                log.Info(message);
            }
            log = null;
        }
        public static void Error(string message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(ErrLoggerName);
            if (log.IsErrorEnabled)
            {
                Console.WriteLine($"{DateTime.Now}-{message}");
                log.Error(message);
            }
            log = null;
        }
        public static void Warn(string message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(ErrLoggerName);
            if (log.IsWarnEnabled)
            {
                Console.WriteLine($"{DateTime.Now}-{message}");
                log.Warn(message);
            }
            log = null;
        }
    }
}