LogManager.cs
1.7 KB
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
using System;
namespace eyemLib_Sharp.log4cpp
{
public class LogManager : Log4CPPBase, ILog4CPP
{
public LogManager(string filepath, string filename, GenerateMode generateMode = GenerateMode.ByEveryHour)
{
m_filePath = filepath;
m_fileName = filename;
m_generateMode = generateMode;
}
/// <summary>
/// 文件的路径
/// </summary>
private string m_filePath = string.Empty;
/// <summary>
/// 文件名称
/// </summary>
private string m_fileName = string.Empty;
private GenerateMode m_generateMode = GenerateMode.ByEveryHour;
protected override string GetLogFilePath()
{
if (string.IsNullOrEmpty(m_filePath)) return string.Empty;
switch (m_generateMode)
{
case GenerateMode.ByEveryMinitues:
return m_filePath + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分") + m_fileName + ".txt";
case GenerateMode.ByEveryHour:
return m_filePath + DateTime.Now.ToString("yyyy年MM月dd日HH时") + m_fileName + ".txt";
case GenerateMode.ByEveryDay:
return m_filePath + DateTime.Now.ToString("yyyy年MM月dd日") + m_fileName + ".txt";
default: return string.Empty;
}
}
public string[] GetExistLogFileNames()
{
if (!string.IsNullOrEmpty(m_filePath))
{
return System.IO.Directory.GetFiles(m_filePath, "*.txt");
}
else
{
return new string[] { };
}
}
}
}