Log file in Dynamics Nav

PloegPloeg Member Posts: 70
edited 2012-01-09 in NAV Three Tier
Howdy-ho fellow NAV'ers,

I would like to know if there is a log file available for/in Dynamics Nav in which I can find errors or warnings? My searchings across the internet haven't been very succesfull.

If there is no log file I'm going to try and build my own log. ](*,)

Comments

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Errors or messages from the NAV client are not logged but only displayed on the user's screen.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • BeliasBelias Member Posts: 2,998
    you can create your own log file relatively easy by using this structure
    IF NOT CODEUNIT.RUN THEN
      myerrortext := GETLASTERRORTEXT;
    
    and putting your whole process within the run trigger of the codeunit. Of course you can wrap whatever you want in the onrun trigger (another codeunit, some function in tables, etc. etc.). Just be be very careful to keep the transaction (if any) consistent.
    Also, if you open some transaction in your "wrapper" codeunit (you write some table), and you want to recursively use the structure i've said, like
    mytable.findset;
    repeat
      //COMMIT;  // you should place a commit here...
      IF NOT CODEUNIT.RUN THEN
        myerrortext := GETLASTERRORTEXT;
      COMMIT;  // ...or here
    until mytable.next = 0;
    
    you have to run a commit at every loop (this is enforced by NAV).
    Once you practice with this structure, you'll want to use it for every "interface-with-third-party-products" process you create :D. It's very powerful if used wisely.
    If you have some doubts, just ask (or better search mibuso)...but I encourage you to bang your head on it for a day or so ;)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Ploeg wrote:

    If there is no log file I'm going to try and build my own log. ](*,)

    Why?
    David Singleton
  • PloegPloeg Member Posts: 70
    Thanks for the quick replies. So, a homemade log it is.

    @David Singleton - I want to use this to keep track of any errors that pop-up to make testing and bug-fixing less dependable on customer input. And in time I want to expand the log with delete and modify messages, just to "monitor" user actions so we can tell them they have been morons.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Ploeg wrote:
    Thanks for the quick replies. So, a homemade log it is.

    @David Singleton - I want to use this to keep track of any errors that pop-up to make testing and bug-fixing less dependable on customer input. And in time I want to expand the log with delete and modify messages, just to "monitor" user actions so we can tell them they have been morons.

    Ah so basically a reallocation of the Training Budget to the Development budget.

    I never really understood why people are so opposed to training in Navision. I guess the old rule applies,
    a man with a hammer sees every problem as a nail
    David Singleton
  • PloegPloeg Member Posts: 70
    This is partially true. But I have two reasons to want it:
    1- my own practice and experience
    2- quality control of our code and modules

    So in ideal circumstances it would give us a log without errors and but with delete and modify actions of users.
  • julkifli33julkifli33 Member Posts: 1,092
    any way....
    i can create txt file if error
    but how to catch the error message to put it in the log file?
    thanks
  • BeliasBelias Member Posts: 2,998
    @juklifri: GETLASTERRORTEXT function!
    and back to the original topic: I explained how to log an error refers to the fact i was supposing you wanted to monitor and log one single process, not the entire application.
    I probably misunderstood your post. "If codeunit.run" traps the error without showing it, but you, instead, want to write every error that pops up to the user, isn't it? in the latter case, David's suggestion is the way to go (or an homemade log, if you have big time to spend and test!)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • kinekine Member Posts: 12,562
    Only solution I can think of is timer saving GETLASTERRORTEXT if not empty and not already stored. But I am not sure if it can catch everything and will be problematic to debug anything with stop at triggers enabled.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • BeliasBelias Member Posts: 2,998
    What about asking MS for an OnGlobalError function in codeunit 1, just like the onglobalinsert? :roll:
    ..Just some monday morning brainstorming :mrgreen:
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • julkifli33julkifli33 Member Posts: 1,092
    Belias wrote:
    @juklifri: GETLASTERRORTEXT function!
    and back to the original topic: I explained how to log an error refers to the fact i was supposing you wanted to monitor and log one single process, not the entire application.
    I probably misunderstood your post. "If codeunit.run" traps the error without showing it, but you, instead, want to write every error that pops up to the user, isn't it? in the latter case, David's suggestion is the way to go (or an homemade log, if you have big time to spend and test!)

    when the error come, it cant execute the code
    IF NOT SH.INSERT(TRUE) THEN
    StrLine2 := GETLASTERRORTEXT;

    when i want to insert, it has redundant data
    then it cant execute the next code
  • BeliasBelias Member Posts: 2,998
    because there's an error within the oninsert trigger, which is not related to what help online says:
    If you omit this optional return value and if the record cannot be inserted, a run-time error occurs.
    If you have an ERROR('A') in your oninsert trigger, you will get the error message and stop execution and rollback.

    On the other hand, If you use an "IF sh.INSERT(FALSE) THEN" instruction, you will never ever got an error in the GETLASTERRORTEXT, because there's no error at all. because
    If you include the return value, you must handle any errors.

    To try this functionality, write a new codeunit and do this in the onrun trigger:
    ERROR('thisismyerror');
    
    create a new report and do an
    IF not myjustcreatednewcodeunit.RUN then
      MESSAGE(getlasterrortext);
    
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • PloegPloeg Member Posts: 70
    Thanks for all the helpful pointers. I think, for the moment, I'll go for the log which monitors just some of the functions/triggers (Belias' method). That way we can still check some of our less stable pieces of code.

    I'll send MS a request for this, signed, stamped and sealed... in triplicate.
  • BeliasBelias Member Posts: 2,998
    We talked with you about a """tool""" to manage any type of error: i want to remark that is dangerous if not used wisely. Be very very careful to use it. I don't know what will you wrap in the "IF codeunit.run then", so i cannot give you a better suggestion than test, test, test and check data integrity of the involved tables, especially during recursive processes (most common problem is unwanted inserts/modifies). And also, remember that you want the user to receive the popup error!for this,
    ERROR(GETLASTERRORTEXT);
    
    should do the job
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • julkifli33julkifli33 Member Posts: 1,092
    Belias wrote:
    because there's an error within the oninsert trigger, which is not related to what help online says:
    If you omit this optional return value and if the record cannot be inserted, a run-time error occurs.
    If you have an ERROR('A') in your oninsert trigger, you will get the error message and stop execution and rollback.

    On the other hand, If you use an "IF sh.INSERT(FALSE) THEN" instruction, you will never ever got an error in the GETLASTERRORTEXT, because there's no error at all. because
    If you include the return value, you must handle any errors.

    To try this functionality, write a new codeunit and do this in the onrun trigger:
    ERROR('thisismyerror');
    
    create a new report and do an
    IF not myjustcreatednewcodeunit.RUN then
      MESSAGE(getlasterrortext);
    

    hi Belias,
    the problem is i create this code in codeunit
    and i put the condition code in C# webservice, not from NAV it self
    so I a little bit confuse where should i put this
    IF not myjustcreatednewcodeunit.RUN then
      MESSAGE(getlasterrortext);
    
Sign In or Register to comment.