/*=====================================================================================*\
|| # Baboh Emulator Project ||
|+=====================================================================================+|
|| # Copyright © 2009 Baboh Team. All rights reserved. ||
|| # http://www.BabohEmulator.net ||
|+=====================================================================================+|
|| # This file is part of The Baboh Server Project. ||
|+=====================================================================================+|
|| # The Baboh Server Project 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. ||
|+=====================================================================================+|
|| # The Baboh Server Project 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 The Baboh Server Project. If not, see . ||
|| # warrenty of any kind. BabohCMS is free software! ||
\*=====================================================================================*/
using System;
using System.IO;
using System.Drawing;
using Holo;
namespace Holo.Core
{
///
/// Provides various functions for logging events to the main form and optionally to disk.
///
public static class Logging
{
#region Declares
///
/// A reference to the main form.
///
public static frmMain mainForm;
///
/// Specifies if to save logs to disk.
///
public static bool saveLogsToDisk = true;
///
/// Specifies if to log info messages.
///
public static bool logInfoMessages = true;
///
/// Specifies if to log warnings.
///
public static bool logWarnings = true;
///
/// Specifica se loggare le "linee speciali".
///
public static bool logSpecialLines = true;
///
/// Specifies if to log errors.
///
public static bool logErrors = true;
///
/// Specifies if to log client>server messages.
///
public static bool logClientMessages = false;
///
/// Specifies if to log server>client messages.
///
public static bool logServerMessages = false;
#endregion
public static void logHolyInfo(string Text)
{
System.Windows.Forms.Application.DoEvents();
mainForm.logInfo(Text);
}
///
/// Logs a plain line of text with a >, which is never written to logfile.
///
/// The text to log.
public static void logInfo(string Text)
{
if (logInfoMessages)
mainForm.logInfo(">> " + Text);
}
///
/// Logs a warning message with timestamp and assembly name.
///
/// The text to log.
public static void logWarning(string Text)
{
if (logWarnings)
mainForm.logWarning(Text);
}
///
/// Logs an error message with timestamp and assembly name.
///
/// The text to log.
public static void logSpecialLine(string logText)
{
if (logSpecialLines)
mainForm.logSpecialLine(logText);
}
/// Logs an error message with timestamp and assembly name.
///
/// The text to log.
public static void logError(string Text)
{
if (logErrors)
mainForm.logError(Text);
}
public static void logClientMessage(int connectionID, string Message)
{
if (logClientMessages)
mainForm.logClientMessage(connectionID, Message);
}
public static void logServerMessage(int connectionID, string Message)
{
if (logServerMessages)
mainForm.logServerMessage(connectionID, Message);
}
///
/// Creates a TextWriter instance and writes a string to the current log file in the /logs/ folder of the application.
///
/// The string to write.
public static void writeLogToFile(string s)
{
try
{
TextWriter Writer = new StreamWriter(IO.startupPath + "/logs/" + DateTime.Now.ToShortDateString() + ".txt", true);
Writer.Write(s);
Writer.Flush();
Writer.Close();
Writer.Dispose();
}
catch { }
}
}
}