cdk
3 天以前 91d3b71e4ff6884ae4c064929b0071ed98363ff9
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
// Decompiled with JetBrains decompiler
// Type: ChengZhongModbus.LoggerHelper
// Assembly: ChengZhongModbusIQC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 335383E6-9854-4BCE-8CD7-BF94F8E1A377
// Assembly location: C:\Users\Administrator\Desktop\ChengZhongModbusIQC\ChengZhongModbusIQC.exe
 
using DevExpress.Xpo.Logger;
using System;
using System.Configuration;
using System.IO;
 
public class LoggerHelper
{ //创建日志目录
    private static readonly string path = AppContext.BaseDirectory +
                                          ConfigurationManager.AppSettings[
                                              "LogPath"];
    /**
       * 实际的写日志操作
       * @param type 日志记录类型
       * @param className 类名
       * @param content 写入内容
       */
    protected static void WriteLog(string type, string className,
        string content)
    {
        if (!Directory.Exists(path)) //如果日志目录不存在就创建
            Directory.CreateDirectory(path);
        var time =
            DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); //获取当前系统时间
        var filename = path + "/" + DateTime.Now.ToString("yyyy-MM-dd") +
                       ".log"; //用日期对日志文件命名
                               //创建或打开日志文件,向日志文件末尾追加记录
        var mySw = File.AppendText(filename);
        //向日志文件写入内容
        var write_content =
            time + " " + type + " " + className + ": " + content;
        mySw.WriteLine(write_content);
        //关闭日志文件
        mySw.Close();
    }
 
 
    public static void WriteInfoLog(string info)
    {
        WriteLog("DEBUG", "", info);
    }
 
    public static void WriteErrorLog(string info)
    {
        WriteLog("DEBUG", "", info);
    }
}