markus / MarkusAutoUpdate / src / NetSparkle / LogWriter.cs @ d8f5045e
이력 | 보기 | 이력해설 | 다운로드 (1.98 KB)
1 | d8f5045e | taeseongkim | using NetSparkleUpdater.Enums; |
---|---|---|---|
2 | using NetSparkleUpdater.Interfaces; |
||
3 | using System; |
||
4 | using System.Collections.Generic; |
||
5 | using System.Diagnostics; |
||
6 | using System.Linq; |
||
7 | using System.Text; |
||
8 | using System.Threading.Tasks; |
||
9 | |||
10 | namespace NetSparkleUpdater |
||
11 | { |
||
12 | /// <summary> |
||
13 | /// A simple class to handle log information for NetSparkleUPdater. |
||
14 | /// Make sure to do any setup for this class that you want |
||
15 | /// to do before calling StartLoop on your SparkleUpdater object. |
||
16 | /// </summary> |
||
17 | public class LogWriter : ILogger |
||
18 | { |
||
19 | /// <summary> |
||
20 | /// Tag to show before any log statements |
||
21 | /// </summary> |
||
22 | public static string tag = "netsparkle:"; |
||
23 | /// <summary> |
||
24 | /// Empty constructor -> sets PrintDiagnosticToConsole to false |
||
25 | /// </summary> |
||
26 | public LogWriter() |
||
27 | { |
||
28 | PrintDiagnosticToConsole = false; |
||
29 | } |
||
30 | |||
31 | /// <summary> |
||
32 | /// LogWriter constructor that takes a bool to determine |
||
33 | /// the value for printDiagnosticToConsole |
||
34 | /// </summary> |
||
35 | /// <param name="printDiagnosticToConsole">Whether this object should print via Debug.WriteLine or Console.WriteLine</param> |
||
36 | public LogWriter(bool printDiagnosticToConsole) |
||
37 | { |
||
38 | PrintDiagnosticToConsole = printDiagnosticToConsole; |
||
39 | } |
||
40 | |||
41 | #region Properties |
||
42 | |||
43 | /// <summary> |
||
44 | /// True if this class should print to Console.WriteLine; |
||
45 | /// false if this object should print to Debug.WriteLine. |
||
46 | /// Defaults to false. |
||
47 | /// </summary> |
||
48 | public bool PrintDiagnosticToConsole { get; set; } |
||
49 | |||
50 | #endregion |
||
51 | |||
52 | /// <inheritdoc/> |
||
53 | public virtual void PrintMessage(string message, params object[] arguments) |
||
54 | { |
||
55 | if (PrintDiagnosticToConsole) |
||
56 | { |
||
57 | Console.WriteLine(tag + " " + message, arguments); |
||
58 | } |
||
59 | else |
||
60 | { |
||
61 | Debug.WriteLine(tag + " " + message, arguments); |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | } |