Exemple #1
0
        /// <summary>
        /// Create a log entry
        /// </summary>
        /// <param name="message">Log message</param>
        /// <param name="color">Color of the message</param>
        /// <param name="onlyShowInLog">Show in Log window only</param>
        /// <param name="onlyShowInStatus">Send bare til status feltet</param>
        /// <param name="onlyShowInLogFile">Send bare til fil</param>
        public static void n(string message, Color? color = null, bool onlyShowInLog = false, bool onlyShowInStatus = false, bool onlyShowInLogFile = false, bool isDebug = false, bool isSqlDebug = false)
        {
            if (isDebug || isSqlDebug)
                Console.WriteLine("Debug: " + message);

            var logObject = new KgsaLog(message, color, onlyShowInLog, onlyShowInStatus, onlyShowInLogFile, isDebug, isSqlDebug);

            log.Add(logObject);

            if (LogAdded != null)
                LogAdded(null, EventArgs.Empty);
        }
Exemple #2
0
        private void InvokeLogger(KgsaLog log)
        {
            try
            {
                if (log == null)
                    return;

                if (log.debug && !appConfig.debug) // hvis det er en debug melding og debug er ikke aktivert; ikke send melding!
                    return;

                if (log.debugSql && !appConfig.debugSql) // hvis det er en debug SQL melding og debug SQL er ikke aktivert; ikke send melding!
                    return;

                string str = log.message;
                str = str.Trim();
                str = str.Replace("\n", " ");
                str = str.Replace("\r", String.Empty);
                str = str.Replace("\t", String.Empty);

                if (!log.fileonly && !log.logonly && !log.debug)
                    ClearMessageTimer();

                var file = new StreamWriter(settingsPath + @"\Log.txt", true, Encoding.Unicode);
                DateTime t = DateTime.Now;
                string logLine = "";
                if (log.debug)
                    logLine = t.ToShortDateString() + " - " + t.ToShortTimeString() + ":" + t.ToString("ss") + " (debug) : " + str;
                else
                    logLine = t.ToShortDateString() + " - " + t.ToShortTimeString() + ":" + t.ToString("ss") + " : " + str;
                if (!log.statusonly)
                    file.WriteLine(logLine);
                file.Close();
                if (!log.debug)
                    AddToLoggCache(t.ToShortTimeString() + ":" + t.ToString("ss") + " : " + str); // Lagre til cache, for bruk til async stuff

                if (!log.fileonly)
                {
                    if (!log.logonly)
                    {
                        toolStripStatusLabel1.ForeColor = log.color;
                        toolStripStatusLabel1.Text = str;
                        statusStrip.Refresh();
                    }

                    if (!log.statusonly)
                    {
                        richLog.AppendText(logLine + Environment.NewLine, log.color);
                        richLog.ScrollToCaret();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Kritisk feil i logg system.\n" + ex.Message, "KGSA - Feil", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }