예제 #1
0
        /// <summary>
        /// Add a date and symbol to the message
        /// </summary>
        /// <param name="message"></param>
        /// <param name="verbocity"></param>
        /// <returns></returns>
        private string BuildLogEntry(object message, DebugVerbocity verbocity)
        {
            string information    = "";
            string datetime       = DateTime.Now.ToString("MMM dd yyyy hh:mm:ss");
            string severitySymbol = "";

            if (message is Exception)
            {
                Exception exceptionEntry = (Exception)message;
                information = exceptionEntry.Message;
            }
            else if (message is string)
            {
                information = (string)message;
            }

            switch (verbocity)
            {
            case (DebugVerbocity.Informational):
            {
                severitySymbol = "+";
                break;
            }

            case (DebugVerbocity.Warning):
            {
                severitySymbol = "!";
                break;
            }

            case (DebugVerbocity.Exception):
            {
                severitySymbol = "-";
                break;
            }
            }
            return("[" + severitySymbol + "][" + datetime + "]" + information);
        }
예제 #2
0
        /// <summary>
        /// Create a new entry in the logs
        /// </summary>
        /// <param name="message">The message to log (exception or string object)</param>
        /// <param name="verbocity">The level of verbocity this message is mapped to</param>
        public void LogMessage(object message, DebugVerbocity verbocity)
        {
            try
            {
                if (verbocity <= _selectedVerbocity)
                {
                    string logEntry = BuildLogEntry(message, verbocity);
                    if (_shouldWriteToFile)
                    {
                        WriteToFile(logEntry);
                    }
                    if (_shouldWriteToConsole)
                    {
                        Console.WriteLine(logEntry);
                    }

                    // raise event so listeners can do what they like with the log entry
                    OnMessageLogged(logEntry);
                }
            } catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }