public TraceLogsModel GetTraceLogs(string filename)
        {
            try
            {
                ListTraceLogs = new List <TraceLogDataModel>();

                var currentTraceLogFile = Path.Combine(HkLogsService.GetBaseTraceLogPath(), filename);

                if (File.Exists(currentTraceLogFile))
                {
                    var logFile = File.ReadAllLines(currentTraceLogFile);
                    var logList = new List <string>(logFile);

                    foreach (var logEntry in logList)
                    {
                        var match = LogEntryRegex.Match(logEntry);

                        TraceLogDataModel traceLogItem;
                        if (match.Success)
                        {
                            // Get Log Entry Date Format yyyy-MM-dd HH:mm:ss (first 19 chars)
                            var logEntryData = logEntry.Trim().Substring(0, 19);

                            var date = DateTime.Parse(logEntryData);

                            var threadProcess = match.Groups["PROCESS2"].Value;

                            if (string.IsNullOrEmpty(threadProcess))
                            {
                                threadProcess = match.Groups["PROCESS1"].Value;
                            }

                            string threadId  = null;
                            string processId = null;
                            string domainId  = null;

                            if (!string.IsNullOrEmpty(threadProcess))
                            {
                                var procMatches = ThreadProcessRegex.Matches(threadProcess);

                                foreach (Match procMatch in procMatches)
                                {
                                    if (!procMatch.Success)
                                    {
                                        continue;
                                    }
                                    var grp = procMatch.Groups["THREAD"];
                                    if (grp.Success)
                                    {
                                        threadId = grp.Value;
                                    }

                                    grp = procMatch.Groups["PROCESS"];
                                    if (grp.Success)
                                    {
                                        processId = grp.Value;
                                    }

                                    grp = procMatch.Groups["DOMAIN"];
                                    if (grp.Success)
                                    {
                                        domainId = grp.Value;
                                    }

                                    if (threadId != null)
                                    {
                                        continue;
                                    }
                                    grp = procMatch.Groups["THREADOLD"];
                                    if (grp.Success)
                                    {
                                        threadId = grp.Value;
                                    }
                                }
                            }

                            traceLogItem = new TraceLogDataModel
                            {
                                LogDate    = date,
                                LogProcess = processId,
                                LogDomain  = domainId,
                                LogThread  = threadId,
                                LogLevel   = match.Groups["LEVEL"].Value,
                                LogLogger  = match.Groups["LOGGER"].Value,
                                LogMessage = match.Groups["MESSAGE"].Value
                            };

                            ListTraceLogs.Add(traceLogItem);
                        }
                        else
                        {
                            if (ListTraceLogs.Count > 0)
                            {
                                traceLogItem = new TraceLogDataModel
                                {
                                    LogMessage = string.Concat(logEntry)
                                };
                                ListTraceLogs.Add(traceLogItem);
                            }
                        }

                        ListTraceLogs.Sort((x, y) => y.LogDate.CompareTo(x.LogDate));
                        TraceLogsModel.ListTraceLogs = ListTraceLogs;
                    }
                }
                else
                {
                    throw new FileNotFoundException("The requested trace log file '" + Path.GetFileName(currentTraceLogFile) + "' could not be found", currentTraceLogFile);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error <Exception>(ex.Message, ex);
                return(TraceLogsModel);
            }
            return(TraceLogsModel);
        }
        /// <summary>
        /// GetTreeNodes(string id, FormDataCollection queryStrings)
        /// This method create the Base Tree of FALM custom section
        /// </summary>
        /// <param name="id"></param>
        /// <param name="queryStrings"></param>
        /// <returns>tree</returns>
        protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
        {
            var tree        = new TreeNodeCollection();
            var textService = ApplicationContext.Services.TextService;

            // check if we're rendering the root node's children
            if (id == global::Umbraco.Core.Constants.System.Root.ToInvariantString())
            {
                tree = new TreeNodeCollection
                {
                    CreateTreeNode("logs", "-1", queryStrings, textService.Localize("FALM/LogsManager.TreeSection", CultureInfo.CurrentCulture), "icon-list", true, queryStrings.GetValue <string>("application")),
                    CreateTreeNode("media", "-1", queryStrings, textService.Localize("FALM/MediaManager.TreeSection", CultureInfo.CurrentCulture), "icon-umb-media", true, queryStrings.GetValue <string>("application")),
                    CreateTreeNode("users", "-1", queryStrings, textService.Localize("FALM/UsersManager.TreeSection", CultureInfo.CurrentCulture), "icon-users", true, queryStrings.GetValue <string>("application")),
                    CreateTreeNode("versions", "-1", queryStrings, textService.Localize("FALM/VersionsManager.TreeSection", CultureInfo.CurrentCulture), "icon-books", true, queryStrings.GetValue <string>("application"))
                };

                return(tree);
            }
            else
            {
                switch (id)
                {
                case "logs":     // check if we're rendering Logs node's children
                    tree = new TreeNodeCollection {
                        CreateTreeNode("logs-dbmanager", id, queryStrings, textService.Localize("FALM/LogsManager.TreeActionManagerDB", CultureInfo.CurrentCulture), "icon-diagnostics color-green", false),
                        CreateTreeNode("logs-tlmanager", id, queryStrings, textService.Localize("FALM/LogsManager.TreeActionManagerTL", CultureInfo.CurrentCulture), "icon-folder", true, queryStrings.GetValue <string>("application"))
                    };
                    break;

                case "logs-tlmanager":     // check if we're rendering Logs node's children
                    tree = new TreeNodeCollection();

                    // LogService
                    HkLogsService logsService        = new HkLogsService();
                    string        currentMachineName = Environment.MachineName;
                    int           iCount             = 1;

                    // Create TraceLog tree
                    foreach (var logFile in logsService.GetTraceLogFiles())
                    {
                        string title = iCount == 1 ? textService.Localize("FALM/LogsManager.TreeActionManagerTL.Today", CultureInfo.CurrentCulture) : logFile.LogDate.ToString("yyyy-MM-dd");

                        if (logFile.LogMachineName != null && !logFile.LogMachineName.InvariantEquals(currentMachineName))
                        {
                            title += " (" + logFile.LogMachineName + ")";
                        }

                        string path = HttpUtility.UrlEncode(System.IO.Path.GetFileName(logFile.LogFileName));
                        string traceLogRoutePath = queryStrings.GetValue <string>("application") + "/housekeeping/edittl/" + path;

                        tree.Add(CreateTreeNode(path, id, queryStrings, title, "icon-calendar-alt color-green", false, traceLogRoutePath));

                        iCount++;
                    }
                    ;
                    break;

                case "media":     //check if we're rendering Media node's children
                    var mediaPath = queryStrings.GetValue <string>("application") + "/" + this.TreeAlias + "/media-cleanup";
                    tree = new TreeNodeCollection {
                        CreateTreeNode("media-cleanup", id, queryStrings, textService.Localize("FALM/MediaManager.TreeActionCleanup", CultureInfo.CurrentCulture), "icon-delete color-red", false)
                    };
                    break;

                case "users":     //check if we're rendering Users node's children
                    tree = new TreeNodeCollection {
                        CreateTreeNode("users-cleanup", id, queryStrings, textService.Localize("FALM/UsersManager.TreeActionCleanup", CultureInfo.CurrentCulture), "icon-delete color-red", false)
                    };
                    break;

                case "versions":     //check if we're rendering Versions node's children
                    tree = new TreeNodeCollection {
                        CreateTreeNode("versions-manager", id, queryStrings, textService.Localize("FALM/VersionsManager.TreeActionManager", CultureInfo.CurrentCulture), "icon-diagnostics color-green", false),
                    };
                    break;
                }

                return(tree);
            }

            //this tree doesn't suport rendering more than 1 level
            throw new NotSupportedException();
        }
Example #3
0
 /// <summary></summary>
 public HkLogsApiController()
 {
     this.logService = new HkLogsService(UmbracoContext.Application.DatabaseContext.Database, UmbracoContext.Application.ApplicationCache.RuntimeCache);
 }