NAV Logging

Estimated reading time: 7 minutes

Have you ever wished you could see into the past? What is the most natural thing in the world with photo albums and television is almost impossible with Navision or Business Central.

And yet it is so necessary, and so helpful! Because an old programmer wisdom says: Programming is debugging. Another piece of wisdom says: 90/20 errors... At 90% the error is 20 cm in front of the keyboard... only: How do you want to conduct such dialogs?
ProgrammerThe only thing that can lead to this error message is if you type the word „penguin“ in the „Quantity“ field. Have you done this?
UsersMe? Never!

How nice it would be if you could now look back perhaps 1 or 2 hours to see what the user actually entered at this point...


Navision & Business Central 365 log functions

In general, you only have these resources:
ChangelogDepending on the change frequency in the tables, logging via the change log will quickly fill up your database. Information that is no longer relevant and is 5 years old competes with minute-by-minute changes, e.g. in sales lines and financial accounting sheets. Added to this is the load on the server and in the database, combined with table locking. It is not without reason that I have written a separate article on this, which Clean up a Navision database„ or “Clean up and reduce the size of a Navision database„ describes in more detail.
Modified on: The master data of Navision or Business Central usually contains the field "Changed on" (supplemented by most companies with "Changed by" and "Created on/by"). Although this saves a lot of space, it tells you when the last change was made to this record, but not which change.
Guess. "If it says this now, it could have said this before."
Data backups. In a nice Navision and Business Central development environment, for example, you have an automatic development version for every day of the month for the last 30 days, which you can look up at any time. But even this only reveals the actual status at the time of the data backup.
Debugger: Unfortunately, this only allows you to research the current status of Business Central & Navision, and that only with an immense amount of time. Even if you have a very good idea of where the error could or should occur, you have to use the debugger to watch the same program code at work over and over again in endlessly long sessions around critical code. This is about as productive and exciting as watching paint dry.

The solutionFile logging. A generic, easy-to-call and always the same function is used to write the information you specify per day/session to a file („a Navision Log is written“, or, shorter: Navision (or Business central 365) Data is logged).
Older versions of the log are automatically deleted, so that even after years only fresh information on the latest program versions is available.

As there is no competition between processes, this solution is very fast and lock-free. And the database is not cluttered with 99% unnecessary information, as is the case with other Navision log functions, namely the changelog.

Navision log in a text file

You decide for yourself when and where you write which information („logging“ or. write to the Navision log). e.g. filters set, records found, sorting selected:

Screenshot of somewhat more complicated Navision / Business Central program code, enriched with debugging information for troubleshooting.

In the log, you can then comfortably view the compressed results in the Navision Log and don't have to tap through the Business Central debugger with bleeding fingers:

10:11:45. 67,PAGE 50195,20-FA-10572,Find correct column,Status=CONST(Released),FA-No.=CONST(10572),Routing ref.no.=CONST(10000),Routing no.=CONST(000643),Operation no.=CONST(30)
10:11:45. 67,PAGE 50195,20-FA-10572,column found,201
10:11:45. 67,PAGE 50195,20-FA-10572,Age content,0
10:11:45. 83,PAGE 50195,20-FA-10572,Convert duration,Orig: 50,57 active FAs 1 Worker 2
10:11:45. 86,PAGE 50195,20-FA-10572,Old New Total,0 101,14 101,14
10:11:45. 89,PAGE 50195,20-FA-10572,Time updated,BDE:50 minutes 34 seconds/FA:101,14

Since the „Log“ code unit itself is
-Creating a new logging file
-Delete outdated log files (freely adjustable)
-Expand & format the log file
the call (see 1st screenshot) is correspondingly simple.
Since the log file is always stored locally (at least this is my recommendation), and preferably buffered on an SSD or at least RAM cache, logging does not usually delay the regular program flow. Typically, at least 15 log lines per millisecond can be expected. A single incorrectly set filter/key found in this way usually justifies several thousand log lines (from a runtime perspective). But of course it is also important to keep a sense of proportion here: If 10,000 log entries are quickly written to the log file by a loop, this does not leave the processing speed unaffected. How can it? Log entries, like any data processing, also cost time under Navision and Business Central 365 in the end... time!

Since the log function works so quickly and does not cause any other side effects in the system or the database server, inputs, file interfaces (what comes? What goes?), unusual calculations (does the expected result always come out?) etc. can also be monitored in a Navision log file without any problems in the long term.

And in the Navision Log is noticed much more quickly if an expected program code is not run at all, or too often, or in a non-optimal sequence. Or sequences jump unexpectedly, e.g. because key fields have been modified. Unusually long runtimes (every find with more than 7 ms is too long!) also show incorrectly set filters/keys/query strategies at a glance. Endlessly long repetitions indicate pointless iterations - easy to find visually in the Navision log!

In this way, even complex issues can be quickly broken down into logical sub-blocks with comprehensible entry and exit states.

Files that are not needed (experience shows that more than 99.9%) disappear automatically and without residue after one week.

Simple display of the Navision log file with any text editor

Did you know that you can force any file with text content into the text preview in Windows File Explorer? Log files, for example, are not displayed in the preview by default.

Necessary changes in the registry. The first change is necessary for Windows to be able to treat any file with text content as a text file. It does not yet change any display behavior!

EditFlags is already there and will not be changed. The other values:
[HKEY_CLASSES_ROOT]
@=“Textfile“
„Content Type“=“text/plain“
„PerceivedType“=“text“
„PersistentHandler“=“{5e941d80-bf96-11cd-b579-08002b30bfeb}“


And, using the example of *.log files, the registry extensions required for each extension to be displayed as a text file:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT.log]
@=“txtfile“
„PerceivedType“=“text“
„Content Type“=“text/plain“
[HKEY_CLASSES_ROOT.log\PersistentHandler]
@=“{5e941d80-bf96-11cd-b579-08002b30bfeb}“