0

I am using NLog with a VB.Net project:

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

Issues are populated in the log like this:

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

Now, this VB too is a console app that is used my another application which is written with Visual C++. If the parent app has detected that there are problems it displays the log file:

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();
    }
}

The problem is that the log file is in date ascebdung order and sometimes users send me screen shots and don't scroll.

Log

Is there anyway to display this error log from Nlog in fdate desending order? And I don't think it is OK to just read the file in reverse.

I include both VB and C++ tags since I might have to make changes in either tool.


I saw this question Write records in descending order in NLog. The thing is my C# tool uses SimpleLogger and that creates log folders in a folder and the log is named by date, and all items in that log are date descending. But I can't use SimpleLogger with VB.Net I don't think.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • 1
    Why not just load the file into a `vector`, and then just use `rbegin()` for reverse iteration and inserting file-contents into the `dlgLog`. – Rolf Kristensen Nov 02 '20 at 20:44
  • Alternative check your `CTextFileRead` if there is a method to scroll down to the bottom after having loaded the file. – Rolf Kristensen Nov 02 '20 at 20:48
  • @RolfKristensen I'll investigate using the vector. That might be an easy solution. Thank you. – Andrew Truckle Nov 02 '20 at 20:54
  • @RolfKristensen CTextFileRead is from herehttps://www.codeproject.com/Articles/7958/CTextFileDocument and it doesn't have a reverse read. I think I will try the other approach as a temporary workaround. – Andrew Truckle Nov 02 '20 at 20:56
  • 1
    My suggestion about using the scrollbar in `CTextFileRead` does not require any reverse read. It just means scrolling to the bottom automatically after having loaded the file. Just like you can scroll to the bottom of a homepage in your web-browser. – Rolf Kristensen Nov 02 '20 at 21:01
  • @RolfKristensen Ah, I understand now. I'll have a look. There must be a way to post a message to the scrollbar to jump to the bottom. A suggestion here helps:https://forums.codeguru.com/showthread.php?268933-CListbox-scroll-to-last-item. Later on this week I will try! – Andrew Truckle Nov 02 '20 at 21:07

1 Answers1

1

One option could be to load the file into a vector<CString>, and then just use rbegin() for reverse iteration and inserting file-contents into the dlgLog.

Another option is to investigate how update scrollbar in CTextFileRead after having loaded the file, so scroll-button is moved down to the bottom.


Update

I actually was using CEdit control to display the log contents. So in the end I used the following code to automatically scroll to the bottom:

m_editLogData.LineScroll(m_editLogData.GetLineCount());

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70