Skip to content

Commit 07d8d07

Browse files
committed
v0.9.0
1 parent 6ae99f9 commit 07d8d07

File tree

13 files changed

+327
-16
lines changed

13 files changed

+327
-16
lines changed

MABProcessAtWait/Logger.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ class Logger {
99
private static int outputLevel = 2;
1010

1111
private static void Base(string logLevelStr, string message) {
12+
LogRotate();
1213
string logMessage = $"{DateTime.Now.ToString($"yyyy/MM/dd-HH:mm:ss")} [{logLevelStr}]:{message}\n";
1314
Console.WriteLine(logMessage);
1415
File.AppendAllText(logPath, logMessage);
16+
1517
}
1618
public static void Debug(string message) {
1719
if (outputLevel >= 3) {
@@ -44,9 +46,18 @@ public static List<string> GetLogFromFile() {
4446
logs.Reverse();
4547
return logs;
4648
}
47-
4849
public static string GetNearestLogFromFile() {
4950
return GetLogFromFile()[GetLogFromFile().Count - 2];
5051
}
52+
private static void LogRotate() {
53+
List<string> logs = GetLogFromFile();
54+
if (logs.Count >= 1000) {
55+
Console.WriteLine($"LogRotate : { logs[logs.Count - 1]} , {logs[logs.Count - 2]}を削除します");
56+
logs.Remove(logs[logs.Count - 1]);
57+
logs.Remove(logs[logs.Count - 2]);
58+
}
59+
logs.Reverse();
60+
File.WriteAllText(logPath, string.Join("\n", logs.ToArray()));
61+
}
5162
}
5263
}

MainForms/AddInfoButton.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class AddInfoButton :Button {
55

66
public World World { get; set; }
77

8-
private Logger logger = new Logger("MainForm",3);
8+
private Logger logger = new Logger("MainForm");
99

1010
public AddInfoButton(string path) {
1111
logger.Debug(path);

MainForms/AppConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static void WriteAppConfig() {
7171
foreach(string path in AddGameDirPath) {
7272
Text += $"\n{path}";
7373
}
74-
logger.Info(" Writing "+Text);
74+
logger.Info(" Writing "+string.Join(" , ",Text.Split('\n')));
7575
File.WriteAllText(AppConfigPath, Text);
7676
}
7777

MainForms/BackupDataListView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BackupDataListView :ListView {
1313
private ColumnHeader clmnAffiliationWorldName; // '所属ワールド名' 列ヘッダ
1414
private ColumnHeader clmnWorldAffiliationDir; // '所属ディレクトリ' 列ヘッダ
1515

16-
private Logger logger = new Logger("MainForm",3);
16+
private Logger logger = new Logger("MainForm");
1717
public BackupDataListView(World worldObj) {
1818
FullRowSelect = true;
1919
MultiSelect = false;

MainForms/BackupDataPanel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class BackupDataPanel :FlowLayoutPanel {
1111
private FlowLayoutPanel dualPanel;
1212
private FlowLayoutPanel panel;
1313

14-
private Logger logger = new Logger("MainForm",3);
14+
private Logger logger = new Logger("MainForm");
1515
//コンストラクタ
1616
public BackupDataPanel() {
1717
Dock = DockStyle.Fill;

MainForms/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class Config {
1111

1212
public static string ConfigPath = @".\Config\config.txt";
1313

14-
private static Logger logger = new Logger("Config", 3);
14+
private static Logger logger = new Logger("Config");
1515

1616
public static void MakeConfig() {
1717
logger.Info("call:MakeConfig");

MainForms/Logger.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ public Logger(string subProcessName,int outputLevel) {
2121
this.outputLevel = outputLevel;
2222
}
2323

24+
public Logger(string subProcessName) {
25+
this.subProcessName = subProcessName;
26+
this.logPath = $".\\logs\\{subProcessName}.txt";
27+
this.outputLevel = 3;
28+
}
29+
2430
private void Base(string logLevelStr, string message) {
31+
LogRotate();
2532
string logMessage = $"{DateTime.Now.ToString($"yyyy/MM/dd-HH:mm:ss")} [{logLevelStr}]:[{subProcessName}]{message}\n";
2633
Console.WriteLine(logMessage);
27-
if (File.Exists(logPath) == false) {
28-
File.Create(logPath);
29-
}
3034
File.AppendAllText(logPath, logMessage);
3135
}
3236
public void Debug(string message) {
@@ -37,25 +41,33 @@ public void Debug(string message) {
3741
public void Info(string message) {
3842
if (outputLevel >= 2) {
3943
Base("INFO ", message);
44+
4045
}
4146
}
4247
public void Warn(string message) {
4348
if (outputLevel >= 1) {
4449
Base("WARN ", message);
50+
4551
}
4652
}
4753
public void Error(string message) {
4854
if (outputLevel >= 0) {
4955
Base("ERROR", message);
56+
5057
}
5158
}
5259

5360
public List<string> GetLogFromFile() {
5461
List<string> logs = new List<string>();
5562

56-
using (StreamReader s = new StreamReader(this.logPath)) {
57-
string _logs = s.ReadToEnd();
58-
logs = _logs.Split('\n').ToList();
63+
try {
64+
using (StreamReader s = new StreamReader(this.logPath)) {
65+
string _logs = s.ReadToEnd();
66+
logs = _logs.Split('\n').ToList();
67+
}
68+
}
69+
catch (FileNotFoundException) {
70+
File.Create(this.logPath).Close();
5971
}
6072
logs.Reverse();
6173
return logs;
@@ -64,4 +76,15 @@ public List<string> GetLogFromFile() {
6476
public string GetNearestLogFromFile() {
6577
return GetLogFromFile()[GetLogFromFile().Count - 2];
6678
}
79+
80+
private void LogRotate() {
81+
List<string> logs = GetLogFromFile();
82+
if (logs.Count >= 1000) {
83+
Console.WriteLine($"LogRotate : { logs[logs.Count - 1]} , {logs[logs.Count - 2]}を削除します");
84+
logs.Remove(logs[logs.Count - 1]);
85+
logs.Remove(logs[logs.Count - 2]);
86+
}
87+
logs.Reverse();
88+
File.WriteAllText(logPath,string.Join("\n",logs.ToArray()));
89+
}
6790
}

MainForms/RestoreFromBackupForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class RestoreFromBackupForm :Form {
1313
private string pathSrc;
1414
private string pathTar;
1515

16-
private static Logger logger = new Logger("MainForm", 3);
16+
private static Logger logger = new Logger("MainForm");
1717

1818
/*
1919
バックアップオプション

MainForms/Util.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Util {
1010

1111
private static Font fontStyle;
1212

13-
private static Logger logger = new Logger("MainForm",3);
13+
private static Logger logger = new Logger("MainForm");
1414

1515
public static Font FontStyle {
1616
set { fontStyle = value; }

MainForms/WorldListForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class WorldListForm :Form {
2121
//バックアップ画面
2222
private BackupDataPanel backupDataTable;
2323

24-
private Logger logger = new Logger("MainForm",3);
24+
private Logger logger = new Logger("MainForm");
2525

2626
public WorldListForm() {
2727
//Form設定

0 commit comments

Comments
 (0)