1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using System.Diagnostics;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Hive.Client.Common {
|
---|
29 | /// <summary>
|
---|
30 | /// The Logging class uses the Windows Event logging mechanism. It writes the logs to a custom log
|
---|
31 | /// called "Hive Client". For the creation of the Hive Client Log the program must be executed with
|
---|
32 | /// Administrator privileges
|
---|
33 | /// </summary>
|
---|
34 | public class Logging {
|
---|
35 | private static Logging instance = null;
|
---|
36 | private EventLog eventLogger = null;
|
---|
37 |
|
---|
38 | /// <summary>
|
---|
39 | /// This is an implementation of the singleton design pattern.
|
---|
40 | /// </summary>
|
---|
41 | /// <returns>the instance of the logger</returns>
|
---|
42 | public static Logging Instance {
|
---|
43 | get {
|
---|
44 | if (instance == null)
|
---|
45 | instance = new Logging();
|
---|
46 | return instance;
|
---|
47 | }
|
---|
48 | set {}
|
---|
49 | }
|
---|
50 |
|
---|
51 | static Logging GetInstance() {
|
---|
52 | if (instance == null)
|
---|
53 | instance = new Logging();
|
---|
54 | return instance;
|
---|
55 | }
|
---|
56 |
|
---|
57 | private Logging() {
|
---|
58 | eventLogger = new EventLog("Hive Client");
|
---|
59 | }
|
---|
60 |
|
---|
61 | /// <summary>
|
---|
62 | /// Writes an Info Log-Entry
|
---|
63 | /// </summary>
|
---|
64 | /// <param name="source">string representation of the caller</param>
|
---|
65 | /// <param name="message">the message</param>
|
---|
66 | public void Info(String source, String message) {
|
---|
67 | eventLogger.Source = source;
|
---|
68 | eventLogger.WriteEntry(message);
|
---|
69 | eventLogger.Close();
|
---|
70 | }
|
---|
71 |
|
---|
72 | /// <summary>
|
---|
73 | /// Writes an Error Log-Entry
|
---|
74 | /// </summary>
|
---|
75 | /// <param name="source">string representation of the caller</param>
|
---|
76 | /// <param name="message">the message</param>
|
---|
77 | public void Error(String source, String message) {
|
---|
78 | eventLogger.Source = source;
|
---|
79 | //, EventLogEntryType.Error
|
---|
80 | eventLogger.WriteEntry(message);
|
---|
81 | eventLogger.Close();
|
---|
82 | }
|
---|
83 |
|
---|
84 | /// <summary>
|
---|
85 | /// Writes an Error Log-Entry
|
---|
86 | /// </summary>
|
---|
87 | /// <param name="source">string representation of the caller</param>
|
---|
88 | /// <param name="message">the message</param>
|
---|
89 | /// <param name="e">the exception</param>
|
---|
90 | public void Error(String source, String message, Exception e) {
|
---|
91 | eventLogger.Source = source;
|
---|
92 | eventLogger.WriteEntry(message +"\n" + e.ToString());
|
---|
93 | eventLogger.Close();
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|