diff --git a/BrotherPrinterDocument.cs b/BrotherPrinterDocument.cs index d33eaf6..156473f 100644 --- a/BrotherPrinterDocument.cs +++ b/BrotherPrinterDocument.cs @@ -63,7 +63,7 @@ public void Print(Dictionary 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; } @@ -86,8 +86,6 @@ public void Close() // this._document.EndPrint(); this._document.Close(); - - // Console.WriteLine("[DEBUG] プリンターオブジェクトが解放されました。"); } /// diff --git a/ConfigurationManager.cs b/ConfigurationManager.cs index e36c05b..981a5c4 100644 --- a/ConfigurationManager.cs +++ b/ConfigurationManager.cs @@ -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; } diff --git a/MyLogger.cs b/MyLogger.cs new file mode 100644 index 0000000..5c83b9b --- /dev/null +++ b/MyLogger.cs @@ -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}"); + } + } +} diff --git a/Program.cs b/Program.cs index c4921a0..8646a74 100644 --- a/Program.cs +++ b/Program.cs @@ -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); } } }