Skip to content

Commit 3007b07

Browse files
committed
#64 #62 の修正
1 parent 5ba2466 commit 3007b07

File tree

2 files changed

+85
-85
lines changed

2 files changed

+85
-85
lines changed

Zipper/Logger.cs

Lines changed: 81 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,103 +2,102 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using Zipper;
56

6-
public class Logger {
7-
private const int DEFAULT_OUTPUT_LEVEL = 3;
8-
private const int MAX_LOG_COUNT = 500;
9-
private const string LOG_OUTPUT_PATH = ".\\logs";
10-
private string logPath;
11-
private int outputLevel;
12-
private string subProcessName;
7+
namespace Zipper {
8+
public class Logger {
9+
private const int DEFAULT_OUTPUT_LEVEL = 3;
10+
private const int MAX_LOG_COUNT = 500;
11+
private const string LOG_OUTPUT_PATH = ".\\logs";
12+
private string logPath;
13+
private int outputLevel;
14+
private string subProcessName;
1315

14-
public Logger(string subProcessName, string logPath, int outputLevel) {
15-
this.subProcessName = subProcessName;
16-
this.logPath = logPath;
17-
this.outputLevel = outputLevel;
18-
LogRotate();
19-
}
20-
21-
public Logger(string subProcessName, int outputLevel) {
22-
this.subProcessName = subProcessName;
23-
this.logPath = $".\\logs\\{subProcessName}.log";
24-
this.outputLevel = outputLevel;
25-
if (Directory.Exists(LOG_OUTPUT_PATH) == false) {
26-
Directory.CreateDirectory(LOG_OUTPUT_PATH);
16+
public Logger(string subProcessName, string logPath, int outputLevel) {
17+
this.subProcessName = subProcessName;
18+
this.logPath = logPath;
19+
this.outputLevel = outputLevel;
20+
LogRotate();
2721
}
28-
LogRotate();
29-
}
30-
public Logger(string subProcessName, string logPath) {
31-
this.subProcessName = subProcessName;
32-
this.logPath = $".\\logs\\{subProcessName}.log";
33-
this.outputLevel = DEFAULT_OUTPUT_LEVEL;
34-
if (Directory.Exists(LOG_OUTPUT_PATH) == false) {
35-
Directory.CreateDirectory(LOG_OUTPUT_PATH);
22+
public Logger(string subProcessName, int outputLevel) {
23+
this.subProcessName = subProcessName;
24+
this.logPath = $".\\logs\\{subProcessName}.log";
25+
this.outputLevel = outputLevel;
26+
if (Directory.Exists(LOG_OUTPUT_PATH) == false) {
27+
Directory.CreateDirectory(LOG_OUTPUT_PATH);
28+
}
29+
LogRotate();
30+
}
31+
public Logger(string subProcessName, string logPath) {
32+
this.subProcessName = subProcessName;
33+
this.logPath = $".\\logs\\{subProcessName}.log";
34+
this.outputLevel = DEFAULT_OUTPUT_LEVEL;
35+
if (Directory.Exists(LOG_OUTPUT_PATH) == false) {
36+
Directory.CreateDirectory(LOG_OUTPUT_PATH);
37+
}
38+
LogRotate();
3639
}
37-
LogRotate();
38-
}
3940

40-
public Logger(string subProcessName) {
41-
this.subProcessName = subProcessName;
42-
this.logPath = $".\\logs\\{subProcessName}.log";
43-
this.outputLevel = DEFAULT_OUTPUT_LEVEL;
44-
if (Directory.Exists(LOG_OUTPUT_PATH) == false) {
45-
Directory.CreateDirectory(LOG_OUTPUT_PATH);
41+
public Logger(string subProcessName) {
42+
this.subProcessName = subProcessName;
43+
this.logPath = $".\\logs\\{subProcessName}.log";
44+
this.outputLevel = DEFAULT_OUTPUT_LEVEL;
45+
if (Directory.Exists(LOG_OUTPUT_PATH) == false) {
46+
Directory.CreateDirectory(LOG_OUTPUT_PATH);
47+
}
48+
LogRotate();
4649
}
47-
LogRotate();
48-
}
4950

50-
private void Base(string logLevelStr, string message) {
51-
string logMessage = $"{DateTime.Now.ToString($"yyyy/MM/dd-HH:mm:ss")} [{logLevelStr}]:[{subProcessName}]{message}\n";
52-
Console.WriteLine(logMessage);
53-
File.AppendAllText(logPath, logMessage);
54-
}
55-
public void Debug(string message) {
56-
if (outputLevel >= 3) {
57-
Base("DEBUG", message);
51+
private void Base(string logLevelStr, string message) {
52+
string logMessage = $"{DateTime.Now.ToString($"yyyy/MM/dd-HH:mm:ss")} [{logLevelStr}]:[{subProcessName}]{message}\n";
53+
Console.WriteLine(logMessage);
54+
Program.logs.Push(logMessage);
55+
File.AppendAllText(logPath, logMessage);
5856
}
59-
}
60-
public void Info(string message) {
61-
if (outputLevel >= 2) {
62-
Base("INFO ", message);
57+
public void Debug(string message) {
58+
if (outputLevel >= 3) {
59+
Base("DEBUG", message);
60+
}
6361
}
64-
}
65-
public void Warn(string message) {
66-
if (outputLevel >= 1) {
67-
Base("WARN ", message);
68-
62+
public void Info(string message) {
63+
if (outputLevel >= 2) {
64+
Base("INFO ", message);
65+
}
6966
}
70-
}
71-
public void Error(string message) {
72-
if (outputLevel >= 0) {
73-
Base("ERROR", message);
74-
67+
public void Warn(string message) {
68+
if (outputLevel >= 1) {
69+
Base("WARN ", message);
70+
}
7571
}
76-
}
77-
78-
public List<string> GetLogFromFile() {
79-
List<string> logs = new List<string>();
80-
81-
try {
82-
using (StreamReader s = new StreamReader(this.logPath)) {
83-
string _logs = s.ReadToEnd();
84-
logs = _logs.Split('\n').ToList();
72+
public void Error(string message) {
73+
if (outputLevel >= 0) {
74+
Base("ERROR", message);
8575
}
8676
}
87-
catch (FileNotFoundException) {
88-
File.Create(this.logPath).Close();
77+
public List<string> GetLogFromFile() {
78+
List<string> logs = new List<string>();
79+
try {
80+
using (StreamReader s = new StreamReader(this.logPath)) {
81+
string _logs = s.ReadToEnd();
82+
logs = _logs.Split('\n').ToList();
83+
}
84+
}
85+
catch (FileNotFoundException) {
86+
File.Create(this.logPath).Close();
87+
}
88+
//logs.Reverse();
89+
return logs;
8990
}
90-
//logs.Reverse();
91-
return logs;
92-
}
9391

94-
private void LogRotate() {
95-
Info("LogRotate");
96-
List<string> logs = GetLogFromFile();
97-
//log総量が1000行を超えている場合は100行削除
98-
while (logs.Count >= MAX_LOG_COUNT) {
99-
logs.RemoveAt(0);
92+
private void LogRotate() {
93+
Debug("LogRotate");
94+
List<string> logs = GetLogFromFile();
95+
//log総量が1000行を超えている場合は100行削除
96+
while (logs.Count >= MAX_LOG_COUNT) {
97+
logs.RemoveAt(0);
98+
}
99+
//logs.Reverse();
100+
File.WriteAllText(logPath, string.Join("\n", logs.ToArray()));
100101
}
101-
//logs.Reverse();
102-
File.WriteAllText(logPath, string.Join("\n", logs.ToArray()));
103102
}
104103
}

Zipper/WaitDialog.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,29 @@ public partial class WaitDialog :Form {
1818
private TextBox processingContent;
1919
private string[] argsProperty;
2020
public WaitDialog(string[] args) {
21+
Icon = new Icon(".\\image\\app.ico");
2122
argsProperty = args;
2223
Console.WriteLine("WaitDialogを表示しました");
2324
basePanel = new FlowLayoutPanel() {
2425
FlowDirection = FlowDirection.TopDown,
2526
Padding = new Padding(10),
26-
Size = new Size(400, 300),
27+
Size = new Size(600, 300),
2728
};
2829
processingContentLabel = new Label() {
2930
Text = "現在の処理内容 ",
3031
AutoSize = true,
3132
};
3233
processingContent = new TextBox() {
3334
Multiline = true,
34-
Size = new Size(370, 260),
35+
Size = new Size(570, 260),
3536
Anchor = (AnchorStyles.Right) | (AnchorStyles.Bottom),
3637
ScrollBars = ScrollBars.Vertical,
3738
BackColor = ColorTranslator.FromHtml("0x090909"),
3839
ForeColor = ColorTranslator.FromHtml("0xf3f3f3"),
3940
};
4041
basePanel.Controls.AddRange(new Control[] { processingContentLabel, processingContent });
4142
Controls.Add(basePanel);
42-
ClientSize = new Size(400, 300);
43+
ClientSize = new Size(600, 300);
4344
FormBorderStyle = FormBorderStyle.Fixed3D;
4445
Timer timer = new Timer();
4546
timer.Interval = 100;

0 commit comments

Comments
 (0)