From f567360b7720f31ca1fe44474eea4b600f2399f3 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Fri, 9 Feb 2018 10:03:53 +0100 Subject: [PATCH] Move logger setup to separate method. Refers to #2 --- ATxTray/AutoTxTray.cs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/ATxTray/AutoTxTray.cs b/ATxTray/AutoTxTray.cs index 3b0f9ee..7b4539c 100644 --- a/ATxTray/AutoTxTray.cs +++ b/ATxTray/AutoTxTray.cs @@ -60,21 +60,8 @@ namespace ATxTray private static DirectoryInfo _selectedDir; public AutoTxTray(string baseDir) { - - #region logging configuration - var logConfig = new LoggingConfiguration(); - var fileTarget = new FileTarget { - FileName = Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".log", - Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] ${message}" - // Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] (${logger}) ${message}" - }; - logConfig.AddTarget("file", fileTarget); - var logRule = new LoggingRule("*", LogLevel.Debug, fileTarget); - logConfig.LoggingRules.Add(logRule); - LogManager.Configuration = logConfig; - - #endregion + SetupLogging(); _statusFile = Path.Combine(baseDir, "status.xml"); @@ -124,7 +111,23 @@ namespace ATxTray fsw.Changed += StatusUpdated; fsw.EnableRaisingEvents = true; - Log.Info("AutoTxTray initialization completed."); + Log.Info("{0} initialization completed.", AppTitle); + } + + /// <summary> + /// Configure logging using a file target. + /// </summary> + private static void SetupLogging() { + var logConfig = new LoggingConfiguration(); + var fileTarget = new FileTarget { + FileName = Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".log", + Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] ${message}" + // Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] (${logger}) ${message}" + }; + logConfig.AddTarget("file", fileTarget); + var logRule = new LoggingRule("*", LogLevel.Debug, fileTarget); + logConfig.LoggingRules.Add(logRule); + LogManager.Configuration = logConfig; } private void SetupContextMenu() { -- GitLab