#region License Information /* HeuristicLab * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace HeuristicLab.Hive.Client.Common { /// /// The Logging class uses the Windows Event logging mechanism. It writes the logs to a custom log /// called "Hive Client". For the creation of the Hive Client Log the program must be executed with /// Administrator privileges /// public class Logging { private static Logging instance = null; private EventLog eventLogger = null; /// /// This is an implementation of the singleton design pattern. /// /// the instance of the logger public static Logging getInstance() { if (instance == null) instance = new Logging(); return instance; } private Logging() { eventLogger = new EventLog("Hive Client"); } /// /// Writes an Info Log-Entry /// /// string representation of the caller /// the message public void Info(String source, String message) { eventLogger.Source = source; eventLogger.WriteEntry(message); eventLogger.Close(); } /// /// Writes an Error Log-Entry /// /// string representation of the caller /// the message public void Error(String source, String message) { eventLogger.Source = source; eventLogger.WriteEntry(message, EventLogEntryType.Error); eventLogger.Close(); } /// /// Writes an Error Log-Entry /// /// string representation of the caller /// the message /// the exception public void Error(String source, String message, Exception e) { eventLogger.Source = source; eventLogger.WriteEntry(message +"\n" + e.ToString(), EventLogEntryType.Error); eventLogger.Close(); } } }