Beispiel #1
0
        static void log(LOG_LEVEL level, string content)
        {
            StackTrace trace = new StackTrace(true);

            StackFrame[] frames = trace.GetFrames();
            App.WriteLog(0, (uint)level, level.ToString(), frames[1].GetFileName(), frames[1].GetMethod().Name, (uint)frames[1].GetFileLineNumber(), content);
        }
Beispiel #2
0
        public static void WriteLog(string FileName, LOG_LEVEL llLogLevel, string LogStr)
        {
            //時間、iLevel、字串,符合Level設定範圍的就寫入log

            string strExt = Path.GetExtension(FileName);

            if (string.IsNullOrEmpty(strExt))
            {
                strExt = ".log";
            }

            string strFile = Path.GetFileNameWithoutExtension(FileName);

            string LogPath   = LOGPATH;//Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + LOGPATH;
            string dateToday = DateTime.Now.ToString("yyyyMMdd", CultureInfo.InvariantCulture);
            string FilePath  = LogPath + strFile + dateToday + strExt;

            // todo: 依照設定顯示不同的log level
            if (IsNeedWritelog(llLogLevel))
            {
                if (!Directory.Exists(LogPath))
                {
                    Directory.CreateDirectory(LogPath);
                }

                lock (m_sLockFlag)
                {
                    try
                    {
                        StreamWriter sw = null;
                        sw = File.AppendText(FilePath);

                        string LevelStr = "(str)";
                        LevelStr  = LevelStr.Replace("str", llLogLevel.ToString());
                        dateToday = DateTime.Now.ToString("yyyy/MM/dd", CultureInfo.InvariantCulture);
                        string timeNow = "[" + dateToday + " " + DateTime.Now.ToString("HH:mm:ss:fff", CultureInfo.InvariantCulture) + "]";
                        sw.WriteLine("{0} {1} {2}",                                 //[時間]  Level  ErrMsg
                                     timeNow,
                                     LevelStr,
                                     LogStr);
                        sw.Flush();
                        sw.Close();
                        sw.Dispose();
                        sw = null;
                    }
                    catch (Exception e)
                    {
                        //Console.WriteLine(e);
                    }
                }
            }
        }
Beispiel #3
0
        public static void WriteLog(LOG_LEVEL llLogLevel, string LogStr)
        {
            //時間、iLevel、字串,符合Level設定範圍的就寫入log

            string strExt = Path.GetExtension(FileName);

            if (strExt == null || strExt.Length == 0)
            {
                strExt = ".log";
            }

            string strFile = Path.GetFileNameWithoutExtension(FileName);

            string LogPath  = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + LOGPATH;
            string FilePath = LogPath + strFile + DateTime.Now.ToString("yyyyMMdd") + strExt;

            // todo: 依照設定顯示不同的log level
            //if (IsNeedWritelog(envirObj, llLogLevel) == true)
            {
                if (!Directory.Exists(LogPath))
                {
                    Directory.CreateDirectory(LogPath);
                }

                lock (m_sLockFlag)
                {
                    try
                    {
                        StreamWriter sw = null;
                        sw = File.AppendText(FilePath);

                        string LevelStr = "(str)";
                        LevelStr = LevelStr.Replace("str", llLogLevel.ToString());

                        sw.WriteLine("{0} {1} {2}",                                 //[時間]  Level  ErrMsg
                                     DateTime.Now.ToString("[yyyy/MM/dd HH:mm:ss:fff]"),
                                     LevelStr, LogStr);
                        sw.Flush();
                        if (sw != null)
                        {
                            sw.Close();
                        }
                    }
                    catch (Exception e)
                    {
                        e.Message.ToString();
                    }
                }
            }
        }
Beispiel #4
0
        public static void s(LOG_LEVEL log_level, string strLog)
        {
            if (!m_logsEnabled)
            {
                return;
            }
            string str = "[" + log_level.ToString() + "]" + strLog;

            if (Log.m_bEnable)
            {
                using (StreamWriter streamWriter = File.AppendText(Log.m_logName))
                    streamWriter.WriteLine(str);
            }
            else
            {
                Console.WriteLine(str);
            }
        }
Beispiel #5
0
 static void log(LOG_LEVEL level, string content)
 {
     App.WriteLog(0, (uint)level, level.ToString(), "DotNetCore", "", 0, content);
 }
Beispiel #6
0
 /// <summary>
 /// 画面部品のリストボックスにログ出力
 /// </summary>
 /// <param name="level"></param>
 /// <param name="log"></param>
 private void LogOut(LOG_LEVEL level, string log)
 {
     listLog.Items.Add($"{DateTime.Now} [{level.ToString()}] {log}");
     listLog.SelectedIndex = listLog.Items.Count - 1;
 }
Beispiel #7
0
    void InitLog(LOG_LEVEL eLevel)
    {
        DirectoryInfo oDir = new DirectoryInfo(Path.GetFullPath("./log/"));

        if (!oDir.Exists)
        {
            oDir.Create();
        }


        int nLevel = (int)eLevel;

        _FileData[nLevel].fs = new FileStream("./log/" + DateTime.Now.Year + "_" + DateTime.Now.Month + DateTime.Now.Day + "_" + DateTime.Now.Hour + DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + eLevel.ToString() + ".log", FileMode.OpenOrCreate);
        _FileData[nLevel].sw = new StreamWriter(_FileData[nLevel].fs, Encoding.Default);
    }
Beispiel #8
0
        /// <summary>
        /// Append logs in the log view
        /// </summary>
        /// <param name="text"></param>
        /// <param name="type"></param>
        private void log(string text, LOG_LEVEL logLevel)
        {
            int paramLogLevelNumber = getLogLevelNumberByText(logLevel.ToString());
            selectedLogLevelNumber = getLogLevelNumberByText(this.comboBox1.SelectedItem.ToString());

            if (paramLogLevelNumber < 0)
            {
                // LOG_LEVEL detected as NONE, only for split line prints
                this.richTextBox1.AppendText(text + System.Environment.NewLine);
            }
            else if (paramLogLevelNumber <= selectedLogLevelNumber)
            {
                // Indicates the specified log level
                int pos = this.richTextBox1.Text.Length;
                string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ": [" + logLevel + "] " + text;
                this.richTextBox1.AppendText(message + System.Environment.NewLine);

                this.richTextBox1.Select(pos, message.Length);
                if (logLevel == LOG_LEVEL.ERROR)
                {
                    this.richTextBox1.SelectionColor = Color.Red;
                }
                else if (logLevel == LOG_LEVEL.WARNING)
                {
                    this.richTextBox1.SelectionColor = Color.Blue;
                }
            }

            //this.richTextBox1.ScrollToCaret();
        }