Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
mass10 committed Jun 1, 2024
1 parent e880cf7 commit b8d1bef
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
4 changes: 1 addition & 3 deletions BrotherPrinterDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Print(Dictionary<string, string> fields)
var field = document.GetObject(e.Key);
if (field == null)
{
Console.WriteLine("[ERROR] field is undefined. key: [{0}]", e.Key);
MyLogger.Error("フィールド [{0}] が未定義です。", e.Key);
continue;
}

Expand All @@ -86,8 +86,6 @@ public void Close()
// this._document.EndPrint();

this._document.Close();

// Console.WriteLine("[DEBUG] プリンターオブジェクトが解放されました。");
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public static ConfigurationManager Configure()
}
}

Console.WriteLine("--dryrun: " + conf.dryrun);
Console.WriteLine("--address-file: " + string.Join(", ", conf.addressFiles));
MyLogger.Info("--dryrun: [", conf.dryrun, "]");
MyLogger.Info("--address-file: [", string.Join(", ", conf.addressFiles), "]");

return conf;
}
Expand Down
44 changes: 44 additions & 0 deletions MyLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PtouchPrintSender
{
class MyLogger
{
private MyLogger()
{

}

//public static void Info(string format, params object[] args)
//{
// var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
// var line = string.Format(format, args);
// Console.WriteLine($"{timestamp} [INFO] {line}");
//}

public static void Info(params object[] args)
{
var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
var line = string.Join("", args);
Console.WriteLine($"{timestamp} [INFO] {line}");
}

//public static void Error(string format, params object[] args)
//{
// var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
// var line = string.Format(format, args);
// Console.WriteLine($"{timestamp} [ERROR] {line}");
//}

public static void Error(params object[] args)
{
var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
var line = string.Join("", args);
Console.WriteLine($"{timestamp} [ERROR] {line}");
}
}
}
6 changes: 5 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ public static void Main(string[] args)
{
try
{
MyLogger.Info("### START ###");

// コンフィギュレーション
var conf = ConfigurationManager.Configure();

// アプリケーションを実行
new Application().Run(conf);

MyLogger.Info("--- END ---");
}
catch (Exception e)
{
Console.WriteLine("[ERROR] 予期しない実行時エラーです。" + e);
MyLogger.Error("予期しない実行時エラーです。" + e);
}
}
}
Expand Down

0 comments on commit b8d1bef

Please sign in to comment.