按日期降序显示 NLog

Displaying NLog in date descending order

我在 VB.Net 项目中使用 NLog:

Private m_logger As NLog.Logger = LogManager.GetCurrentClassLogger()

日志中的问题是这样的:

Catch ex As Exception
    Console.WriteLine("Error: {0}", ex.Message.ToString())
    m_logger.Error(ex, "ExtractCalendarInformation")
End Try

现在,这个 VB 也是一个控制台应用程序,我用另一个用 Visual C++ 编写的应用程序使用它。如果父应用程序检测到存在问题,它会显示日志文件:

void CMeetingScheduleAssistantApp::ShowLogFile(CString strLogFile)
{
    if (PathFileExists(strLogFile))
    {
        CLogDlg dlgLog;

        CTextFileRead fileLog(strLogFile);
        CString strText = _T("");

        fileLog.ReadLine(strText);
        while (!fileLog.Eof())
        {
            strText.Trim();
            if (strText.IsEmpty())
                continue;

            dlgLog.AddLogEntry(strText, true);
            fileLog.ReadLine(strText);
        }

        dlgLog.SetErrorMode(true);
        dlgLog.DoModal();
    }
}

问题是日志文件按日期顺序排列,有时用户会向我发送屏幕截图但不滚动。

有没有办法以 fdate 降序显示来自 Nlog 的错误日志?而且我认为只反向读取文件是不行的。

我同时包含了 VB 和 C++ 标签,因为我可能需要在任一工具中进行更改。


我看到了这个问题Write records in descending order in NLog。问题是我的 C# 工具使用 SimpleLogger 并在文件夹中创建日志文件夹,日志按日期命名,并且该日志中的所有项目都是按日期降序排列的。但是我不认为 SimpleLogger 和 VB.Net 一起使用。

一种选择是将文件加载到 vector<CString>,然后仅使用 rbegin() 进行反向迭代并将 file-contents 插入 dlgLog。

另一种选择是研究如何在加载文件后更新 CTextFileRead 中的滚动条,使 scroll-button 向下移动到底部。


更新

我实际上是在使用CEdit控件来显示日志内容。所以最后我使用了下面的代码自动滚动到底部:

m_editLogData.LineScroll(m_editLogData.GetLineCount());