示例#1
0
        public ActionResult Transition_DeleteLogFile(string id)
        {
            string logFileName = id;

            string logsPath    = MLog.GetLogDirectory();
            string logFilePath = Path.Combine(logsPath, logFileName);

            if (System.IO.File.Exists(logFilePath))
            {
                System.IO.File.Delete(logFilePath);
            }

            return(RedirectToAction("Index"));
        }
示例#2
0
        //
        // GET: /MLog/

        public ActionResult Index(string id)
        {
            string logsPath = MLog.GetLogDirectory();

            List <string> logFiles = null;

            if (Directory.Exists(logsPath))
            {
                logFiles = Directory.GetFiles(logsPath).ToList();
                for (int i = 0; i < logFiles.Count; i++)
                {
                    logFiles[i] = Path.GetFileName(logFiles[i]);
                }
            }


            ViewData["logFiles"] = logFiles;

            List <MLogModel> logs = null;

            // read logFile and send to UI
            if (!string.IsNullOrEmpty(id))
            {
                logs = new List <MLogModel>();

                string logFilePath = Path.Combine(logsPath, id);
                using (StreamReader reader = new StreamReader(logFilePath))
                {
                    string line = reader.ReadLine();
                    while (line != null)
                    {
                        MLogModel log = MLogModel.Parse(line);
                        logs.Add(log);

                        line = reader.ReadLine();
                    }

                    reader.Close();
                }

                ViewData["logs"] = logs;
                ViewData["id"]   = id;
            }

            return(View());
        }
示例#3
0
        public ActionResult Detail(string id)
        {
            string filename   = id.Split('-')[0];
            int    lineNumber = Convert.ToInt32(id.Split('-')[1]);

            // preventing from nullReferanceException
            MLogModel log = new MLogModel();

            string logsPath    = MLog.GetLogDirectory();
            string logFilePath = Path.Combine(logsPath, filename);

            using (StreamReader reader = new StreamReader(logFilePath))
            {
                string line = reader.ReadLine();
                for (int i = 0; line != null; i++)
                {
                    if (lineNumber == i)
                    {
                        if (line.IndexOf('#') != -1)
                        {
                            log = MLogModel.Parse(line);
                        }
                        break;
                    }

                    line = reader.ReadLine();
                }

                reader.Close();
            }

            ViewData["log"]     = log;
            ViewData["logFile"] = filename;

            return(View());
        }