|
4 | 4 | using System.Reflection; |
5 | 5 | using System.Text.RegularExpressions; |
6 | 6 | using System.Xml; |
7 | | -using log4net; |
8 | | -using log4net.Config; |
9 | | -using log4net.Repository.Hierarchy; |
| 7 | +using NLog; |
10 | 8 | using MyNumberNET; |
11 | 9 | using static System.Char; |
12 | 10 |
|
13 | 11 | namespace MyNumberNET_CLI |
14 | 12 | { |
15 | 13 | public class Program |
16 | 14 | { |
17 | | - private static readonly ILog Log = LogManager.GetLogger(typeof(Program)); |
| 15 | + private static readonly Logger Log = LogManager.GetCurrentClassLogger(); |
18 | 16 |
|
19 | 17 | public static int Main(string[] args) |
20 | 18 | { |
21 | 19 | try |
22 | 20 | { |
23 | | - var result = InitializeLogging(); |
24 | | - if (!result) |
25 | | - throw new Exception("Logging could not be enabled."); |
| 21 | + // NLog automatically loads nlog.config, no manual initialization needed |
26 | 22 | } |
27 | 23 | catch (Exception ex) |
28 | 24 | { |
29 | | - Log.Fatal(ex.Message); |
| 25 | + Log.Fatal(ex, ex.Message); |
30 | 26 | return -1; |
31 | 27 | } |
32 | 28 |
|
@@ -183,8 +179,7 @@ public static int Main(string[] args) |
183 | 179 | } |
184 | 180 | catch (Exception ex) |
185 | 181 | { |
186 | | - Log.Fatal(ex.Message); |
187 | | - Log.Debug(ex.StackTrace); |
| 182 | + Log.Fatal(ex, ex.Message); |
188 | 183 | return -1; |
189 | 184 | } |
190 | 185 | } |
@@ -379,32 +374,6 @@ private static int[] Increment(int[] input) |
379 | 374 | return input; |
380 | 375 | } |
381 | 376 |
|
382 | | - /// <summary> |
383 | | - /// Initialize logging |
384 | | - /// </summary> |
385 | | - private static bool InitializeLogging() |
386 | | - { |
387 | | - try |
388 | | - { |
389 | | - // Configuration for logging |
390 | | - var log4NetConfig = new XmlDocument(); |
391 | | - |
392 | | - using (var reader = new StreamReader(new FileStream("log4net.config", FileMode.Open, FileAccess.Read))) |
393 | | - { |
394 | | - log4NetConfig.Load(reader); |
395 | | - } |
396 | | - |
397 | | - var rep = LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(Hierarchy)); |
398 | | - XmlConfigurator.Configure(rep, log4NetConfig["log4net"]); |
399 | | - return true; |
400 | | - } |
401 | | - catch (Exception ex) |
402 | | - { |
403 | | - Console.WriteLine("Error initializing the logging."); |
404 | | - Console.WriteLine(ex.Message); |
405 | | - return false; |
406 | | - } |
407 | | - } |
408 | 377 |
|
409 | 378 | private enum RangeMode |
410 | 379 | { |
|
0 commit comments