コード例 #1
0
        /// <summary>
        /// log the current stack trace
        /// </summary>
        /// <param name="ALoggingtype">destination of logging</param>
        public static void LogStackTrace(TLoggingType ALoggingtype = TLoggingType.ToConsole | TLoggingType.ToLogfile)
        {
            String msg = StackTraceToText(new StackTrace(true));

            msg = msg + "in Appdomain " + AppDomain.CurrentDomain.FriendlyName + Environment.NewLine;
            TLogging.Log(msg, ALoggingtype);
        }
コード例 #2
0
ファイル: Logging.cs プロジェクト: jsuen123/openpetragit
 /// <summary>
 /// Log if level is this high. Output destination can be selected with the Loggingtype flag.
 /// </summary>
 /// <param name="ALevel"></param>
 /// <param name="AText"></param>
 /// <param name="ALoggingType"></param>
 public static void LogAtLevel(Int32 ALevel, string AText, TLoggingType ALoggingType)
 {
     if (TLogging.DebugLevel >= ALevel)
     {
         TLogging.Log(AText, ALoggingType);
     }
 }
コード例 #3
0
ファイル: Logging.cs プロジェクト: merbst/openpetra
        /// <summary>
        /// log the current stack trace; on Mono, that does not fully work
        /// </summary>
        /// <param name="ALoggingtype">destination of logging</param>
        public static void LogStackTrace(TLoggingType ALoggingtype)
        {
            if (Utilities.DetermineExecutingCLR() == TExecutingCLREnum.eclrMono)
            {
                // not printing the stacktrace since that could cause an exception
                return;
            }

            String msg = StackTraceToText(new StackTrace(true));

            msg = msg + "in Appdomain " + AppDomain.CurrentDomain.FriendlyName + Environment.NewLine;
            TLogging.Log(msg, ALoggingtype);
        }
コード例 #4
0
        /// <summary>
        /// Logs a message. Output goes to both Screen and Logfile and - if a callback has been set up with
        /// <see cref="SetStatusBarProcedure"/> or gets passed in with
        /// <paramref name="ACustomStatusCallbackProcedure"/> - to a Status Bar of a Form, too.
        /// </summary>
        /// <param name="Text">Log message</param>
        /// <param name="ACustomStatusCallbackProcedure">Optional instance of a custom callback procedure for writing
        /// to the StatusBar of a Form (default = null).</param>
        public static void Log(string Text, TStatusCallbackProcedure ACustomStatusCallbackProcedure = null)
        {
            TLoggingType loggingType = TLoggingType.ToConsole;

            if (ULogWriter != null)
            {
                loggingType |= TLoggingType.ToLogfile;
            }

            if (StatusBarProcedureValid || (ACustomStatusCallbackProcedure != null))
            {
                loggingType |= TLoggingType.ToStatusBar;
            }

            Log(Text, loggingType);
        }
コード例 #5
0
ファイル: Logging.cs プロジェクト: jsuen123/openpetragit
        /// <summary>
        /// Logs a number of messages in one go. Output destination can be selected
        /// with the Loggingtype flag.
        /// </summary>
        /// <param name="aList">An ArrayList containing a number of Log messages</param>
        /// <param name="isException">If set to TRUE, an information which states that all
        /// following Log messages are Exceptions is written before
        /// the Log messages are logged.</param>
        /// <param name="Loggingtype">logging destination (eg. console, logfile etc)</param>
        /// <returns>void</returns>
        public static void Log(ArrayList aList, bool isException, TLoggingType Loggingtype)
        {
            string additionalInfo;

            additionalInfo = "";

            if (isException)
            {
                additionalInfo = "The application has encountered an Exception: The details are as follows:" + Environment.NewLine;
            }

            Log(Environment.NewLine +
                DateTime.Now.ToLongDateString() + ", " +
                DateTime.Now.ToLongTimeString() + " : " + additionalInfo,
                Loggingtype);

            for (int Counter = 0; Counter <= (aList.Count - 1); Counter++)
            {
                Log(aList[Counter].ToString(), Loggingtype);
            }
        }
コード例 #6
0
ファイル: Logging.cs プロジェクト: jsuen123/openpetragit
        /// <summary>
        /// log the current stack trace; on Mono, that does not fully work
        /// </summary>
        /// <param name="ALoggingtype">destination of logging</param>
        public static void LogStackTrace(TLoggingType ALoggingtype)
        {
            if (Utilities.DetermineExecutingCLR() == TExecutingCLREnum.eclrMono)
            {
                // not printing the stacktrace since that could cause an exception
                return;
            }

            StackTrace st;
            StackFrame sf;
            Int32      Counter;
            String     msg;

            st  = new StackTrace(true);
            msg = "";

            for (Counter = 0; Counter <= st.FrameCount - 1; Counter += 1)
            {
                sf = st.GetFrame(Counter);

                if ((sf.GetMethod().Name == "WndProc") && (sf.GetFileLineNumber() == 0))
                {
                    break;
                }

                msg = msg + "    at " + sf.GetMethod().ToString();

                if (sf.GetFileLineNumber() != 0)
                {
                    msg = msg + " (" + sf.GetFileName() + ": " + sf.GetFileLineNumber().ToString() + ')';
                }

                msg = msg + Environment.NewLine;
            }

            msg = msg + "in Appdomain " + AppDomain.CurrentDomain.FriendlyName + Environment.NewLine;
            TLogging.Log(msg, ALoggingtype);
        }
コード例 #7
0
ファイル: Logging.cs プロジェクト: jsuen123/openpetragit
        /// <summary>
        /// Logs a message. Output destination can be selected with the Loggingtype flag.
        /// </summary>
        /// <param name="Text">Log message</param>
        /// <param name="ALoggingType">Determines the output destination.
        /// Note: More than one output destination can be chosen!</param>
        public static void Log(string Text, TLoggingType ALoggingType)
        {
            if (((ALoggingType & TLoggingType.ToConsole) != 0) ||
                ((ALoggingType & TLoggingType.ToLogfile) != 0)
                // only in Debugmode write the messages for the statusbar also on the console (e.g. reporting progress)
                || (((ALoggingType & TLoggingType.ToStatusBar) != 0) && (TLogging.DebugLevel == TLogging.DEBUGLEVEL_TRACE)))
            {
                Console.Error.WriteLine(Utilities.CurrentTime() + "  " + Text);

                if ((TLogging.Context != null) && (TLogging.Context.Length != 0))
                {
                    Console.Error.WriteLine("  Context: " + TLogging.Context);
                }
            }

            if (((ALoggingType & TLoggingType.ToConsole) != 0) || ((ALoggingType & TLoggingType.ToLogfile) != 0) ||
                ((ALoggingType & TLoggingType.ToStatusBar) != 0))
            {
                if (TLogging.StatusBarProcedureValid && (Text.IndexOf("SELECT") == -1))
                {
                    // don't print sql statements to the statusbar in debug mode

                    if (TLogging.Context.Length != 0)
                    {
                        Text += "; Context: " + TLogging.Context;
                    }

                    StatusBarProcedure(Text);
                }
            }

            if ((ALoggingType & TLoggingType.ToLogfile) != 0)
            {
                if (ULogWriter != null)
                {
                    TLogWriter.Log(Text);

                    if (TLogging.Context.Length != 0)
                    {
                        TLogWriter.Log("  Context: " + TLogging.Context);
                    }
                }
                else
                {
                    // I found it was better to write the actual logging message,
                    // even if the logwriter is not setup up correctly
                    new TLogging("temp.log");
                    TLogWriter.Log(Text);

                    if (TLogging.Context.Length != 0)
                    {
                        TLogWriter.Log("  Context: " + TLogging.Context);
                    }

                    ULogWriter   = null;
                    ULogFileName = null;

                    // now throw an exception, because it is not supposed to work like this
                    throw new ENoLoggingToFile_WrongConstructorUsedException();
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Logs a message. Output destination can be selected with the Loggingtype flag.
        /// </summary>
        /// <param name="Text">Log message</param>
        /// <param name="ALoggingType">Determines the output destination.
        /// Note: More than one output destination can be chosen!</param>
        /// <param name="ACustomStatusCallbackProcedure">Optional instance of a custom callback procedure for writing
        /// to the StatusBar of a Form (default = null).</param>
        public static void Log(string Text, TLoggingType ALoggingType,
                               TStatusCallbackProcedure ACustomStatusCallbackProcedure = null)
        {
            if (((ALoggingType & TLoggingType.ToConsole) != 0) && (ULogTextAsString != null) && (ULogTextAsString.Length > 0))
            {
                // log to static string for Windows Forms app
                if (ULogTextAsString.Length > 16384)
                {
                    TruncateLogString(8192);
                }

                ULogTextAsString += (Utilities.CurrentTime() + "  " + Text + Environment.NewLine);

                if ((TLogging.Context != null) && (TLogging.Context.Length != 0))
                {
                    ULogTextAsString += ("  Context: " + TLogging.Context + Environment.NewLine);
                }

                // Tell our caller that there is a new message
                if (UNewMessageCallback != null)
                {
                    // Can this fail if the program has closed??
                    UNewMessageCallback();
                }
            }
            else if (!FNoLoggingToConsoleError)
            {
                try
                {
                    if (((ALoggingType & TLoggingType.ToConsole) != 0)
                        // only in Debugmode write the messages for the statusbar also on the console (e.g. reporting progress)
                        || (((ALoggingType & TLoggingType.ToStatusBar) != 0) && (TLogging.DebugLevel != 0)))
                    {
                        Console.Error.WriteLine(Utilities.CurrentTime() + "  " + Text);

                        if (!string.IsNullOrEmpty(TLogging.Context))
                        {
                            Console.Error.WriteLine("  Context: " + TLogging.Context);
                        }
                    }
                }
                catch (System.NotSupportedException)
                {
                    // ignore this exception: System.NotSupportedException: Stream does not support writing
                }
            }

            if (((ALoggingType & TLoggingType.ToStatusBar) != 0) &&
                (Text.IndexOf("SELECT") == -1))       // Don't print sql statements to the statusbar
            {
                if (!string.IsNullOrEmpty(TLogging.Context))
                {
                    Text += "; Context: " + TLogging.Context;
                }

                if (ACustomStatusCallbackProcedure == null)
                {
                    if (TLogging.StatusBarProcedureValid)
                    {
                        StatusBarProcedure(Text);
                    }
                }
                else
                {
                    ACustomStatusCallbackProcedure(Text);
                }
            }

            if ((ALoggingType & TLoggingType.ToLogfile) != 0)
            {
                if (ULogWriter != null)
                {
                    TLogWriter.Log(Text);

                    if (TLogging.Context.Length != 0)
                    {
                        TLogWriter.Log("  Context: " + TLogging.Context);
                    }
                }
                else
                {
                    // I found it was better to write the actual logging message,
                    // even if the logwriter is not setup up correctly
                    new TLogging("temp.log");
                    TLogWriter.Log(Text);

                    if (TLogging.Context.Length != 0)
                    {
                        TLogWriter.Log("  Context: " + TLogging.Context);
                    }

                    ULogWriter   = null;
                    ULogFileName = null;

                    // now throw an exception, because it is not supposed to work like this
                    throw new ENoLoggingToFile_WrongConstructorUsedException();
                }
            }
        }
コード例 #9
0
ファイル: Logging.cs プロジェクト: js1987/openpetragit
        /// <summary>
        /// Logs a number of messages in one go. Output destination can be selected
        /// with the Loggingtype flag.
        /// </summary>
        /// <param name="aList">An ArrayList containing a number of Log messages</param>
        /// <param name="isException">If set to TRUE, an information which states that all
        /// following Log messages are Exceptions is written before
        /// the Log messages are logged.</param>
        /// <param name="Loggingtype">logging destination (eg. console, logfile etc)</param>
        /// <returns>void</returns>
        public static void Log(ArrayList aList, bool isException, TLoggingType Loggingtype)
        {
            string additionalInfo;

            additionalInfo = "";

            if (isException)
            {
                additionalInfo = "The application has encountered an Exception: The details are as follows:" + Environment.NewLine;
            }

            Log(Environment.NewLine +
                DateTime.Now.ToLongDateString() + ", " +
                DateTime.Now.ToLongTimeString() + " : " + additionalInfo,
                Loggingtype);

            for (int Counter = 0; Counter <= (aList.Count - 1); Counter++)
            {
                Log(aList[Counter].ToString(), Loggingtype);
            }
        }
コード例 #10
0
ファイル: Logging.cs プロジェクト: js1987/openpetragit
        /// <summary>
        /// log the current stack trace; on Mono, that does not fully work
        /// </summary>
        /// <param name="ALoggingtype">destination of logging</param>
        public static void LogStackTrace(TLoggingType ALoggingtype)
        {
            if (Utilities.DetermineExecutingCLR() == TExecutingCLREnum.eclrMono)
            {
                // not printing the stacktrace since that could cause an exception
                return;
            }

            StackTrace st;
            StackFrame sf;
            Int32 Counter;
            String msg;

            st = new StackTrace(true);
            msg = "";

            for (Counter = 0; Counter <= st.FrameCount - 1; Counter += 1)
            {
                sf = st.GetFrame(Counter);

                if ((sf.GetMethod().Name == "WndProc") && (sf.GetFileLineNumber() == 0))
                {
                    break;
                }

                msg = msg + "    at " + sf.GetMethod().ToString();

                if (sf.GetFileLineNumber() != 0)
                {
                    msg = msg + " (" + sf.GetFileName() + ": " + sf.GetFileLineNumber().ToString() + ')';
                }

                msg = msg + Environment.NewLine;
            }

            msg = msg + "in Appdomain " + AppDomain.CurrentDomain.FriendlyName + Environment.NewLine;
            TLogging.Log(msg, ALoggingtype);
        }
コード例 #11
0
ファイル: Logging.cs プロジェクト: js1987/openpetragit
        /// <summary>
        /// Logs a message. Output destination can be selected with the Loggingtype flag.
        /// </summary>
        /// <param name="Text">Log message</param>
        /// <param name="ALoggingType">Determines the output destination.
        /// Note: More than one output destination can be chosen!</param>
        public static void Log(string Text, TLoggingType ALoggingType)
        {
            if (((ALoggingType & TLoggingType.ToConsole) != 0)
                || ((ALoggingType & TLoggingType.ToLogfile) != 0)
                // only in Debugmode write the messages for the statusbar also on the console (e.g. reporting progress)
                || (((ALoggingType & TLoggingType.ToStatusBar) != 0) && (TLogging.DebugLevel == TLogging.DEBUGLEVEL_TRACE)))
            {
                Console.Error.WriteLine(Utilities.CurrentTime() + "  " + Text);

                if ((TLogging.Context != null) && (TLogging.Context.Length != 0))
                {
                    Console.Error.WriteLine("  Context: " + TLogging.Context);
                }
            }

            if (((ALoggingType & TLoggingType.ToConsole) != 0) || ((ALoggingType & TLoggingType.ToLogfile) != 0)
                || ((ALoggingType & TLoggingType.ToStatusBar) != 0))
            {
                if (TLogging.StatusBarProcedureValid && (Text.IndexOf("SELECT") == -1))
                {
                    // don't print sql statements to the statusbar in debug mode

                    if (TLogging.Context.Length != 0)
                    {
                        Text += "; Context: " + TLogging.Context;
                    }

                    StatusBarProcedure(Text);
                }
            }

            if ((ALoggingType & TLoggingType.ToLogfile) != 0)
            {
                if (ULogWriter != null)
                {
                    TLogWriter.Log(Text);

                    if (TLogging.Context.Length != 0)
                    {
                        TLogWriter.Log("  Context: " + TLogging.Context);
                    }
                }
                else
                {
                    // I found it was better to write the actual logging message,
                    // even if the logwriter is not setup up correctly
                    new TLogging("temp.log");
                    TLogWriter.Log(Text);

                    if (TLogging.Context.Length != 0)
                    {
                        TLogWriter.Log("  Context: " + TLogging.Context);
                    }

                    ULogWriter = null;
                    ULogFileName = null;

                    // now throw an exception, because it is not supposed to work like this
                    throw new ENoLoggingToFile_WrongConstructorUsedException();
                }
            }
        }
コード例 #12
0
ファイル: Logging.cs プロジェクト: js1987/openpetragit
 /// <summary>
 /// Log if level is this high. Output destination can be selected with the Loggingtype flag.
 /// </summary>
 /// <param name="ALevel"></param>
 /// <param name="AText"></param>
 /// <param name="ALoggingType"></param>
 public static void LogAtLevel(Int32 ALevel, string AText, TLoggingType ALoggingType)
 {
     if (TLogging.DebugLevel >= ALevel)
     {
         TLogging.Log(AText, ALoggingType);
     }
 }
コード例 #13
0
ファイル: Logging.cs プロジェクト: Kingefosa/openpetra
        /// <summary>
        /// log the current stack trace; on Mono, that does not fully work
        /// </summary>
        /// <param name="ALoggingtype">destination of logging</param>
        public static void LogStackTrace(TLoggingType ALoggingtype)
        {
            if (Utilities.DetermineExecutingCLR() == TExecutingCLREnum.eclrMono)
            {
                // not printing the stacktrace since that could cause an exception
                return;
            }

            String msg = StackTraceToText(new StackTrace(true));

            msg = msg + "in Appdomain " + AppDomain.CurrentDomain.FriendlyName + Environment.NewLine;
            TLogging.Log(msg, ALoggingtype);
        }
コード例 #14
0
ファイル: Logging.cs プロジェクト: Kingefosa/openpetra
        /// <summary>
        /// Logs a message. Output destination can be selected with the Loggingtype flag.
        /// </summary>
        /// <param name="Text">Log message</param>
        /// <param name="ALoggingType">Determines the output destination.
        /// Note: More than one output destination can be chosen!</param>
        public static void Log(string Text, TLoggingType ALoggingType)
        {
            if (((ALoggingType & TLoggingType.ToConsole) != 0) && (ULogTextAsString != null) && (ULogTextAsString.Length > 0))
            {
                // log to static string for Windows Forms app
                if (ULogTextAsString.Length > 16384)
                {
                    TruncateLogString(8192);
                }

                ULogTextAsString += (Utilities.CurrentTime() + "  " + Text + Environment.NewLine);

                if ((TLogging.Context != null) && (TLogging.Context.Length != 0))
                {
                    ULogTextAsString += ("  Context: " + TLogging.Context + Environment.NewLine);
                }

                // Tell our caller that there is a new message
                if (UNewMessageCallback != null)
                {
                    // Can this fail if the program has closed??
                    UNewMessageCallback();
                }
            }
            else if (((ALoggingType & TLoggingType.ToConsole) != 0)
                     || ((ALoggingType & TLoggingType.ToLogfile) != 0)
                     // only in Debugmode write the messages for the statusbar also on the console (e.g. reporting progress)
                     || (((ALoggingType & TLoggingType.ToStatusBar) != 0) && (TLogging.DebugLevel == TLogging.DEBUGLEVEL_TRACE)))
            {
                Console.Error.WriteLine(Utilities.CurrentTime() + "  " + Text);

                if ((TLogging.Context != null) && (TLogging.Context.Length != 0))
                {
                    Console.Error.WriteLine("  Context: " + TLogging.Context);
                }
            }

            if (((ALoggingType & TLoggingType.ToConsole) != 0) || ((ALoggingType & TLoggingType.ToLogfile) != 0)
                || ((ALoggingType & TLoggingType.ToStatusBar) != 0))
            {
                if (TLogging.StatusBarProcedureValid && (Text.IndexOf("SELECT") == -1))
                {
                    // don't print sql statements to the statusbar in debug mode

                    if (TLogging.Context.Length != 0)
                    {
                        Text += "; Context: " + TLogging.Context;
                    }

                    StatusBarProcedure(Text);
                }
            }

            if ((ALoggingType & TLoggingType.ToLogfile) != 0)
            {
                if (ULogWriter != null)
                {
                    TLogWriter.Log(Text);

                    if (TLogging.Context.Length != 0)
                    {
                        TLogWriter.Log("  Context: " + TLogging.Context);
                    }
                }
                else
                {
                    // I found it was better to write the actual logging message,
                    // even if the logwriter is not setup up correctly
                    new TLogging("temp.log");
                    TLogWriter.Log(Text);

                    if (TLogging.Context.Length != 0)
                    {
                        TLogWriter.Log("  Context: " + TLogging.Context);
                    }

                    ULogWriter = null;
                    ULogFileName = null;

                    // now throw an exception, because it is not supposed to work like this
                    throw new ENoLoggingToFile_WrongConstructorUsedException();
                }
            }
        }