Plugin crash log no longer working

This forum is for programmers who have questions about the source code.
Post Reply
User avatar
wjstarck
Posts: 945
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Plugin crash log no longer working

Post by wjstarck » Fri Jul 26, 2024 6:42 am

Hello-

I have this code at the bottom of Plugin.cs in my plugin.

Code: Select all

       public override void HookException(Exception e) {
           Logging.LogException(e);
           System.Windows.Forms.MessageBox.Show(LanThis, "There was an error with the Anesthesia plugin. Please contact Big Idea Software at 817-807-1709 or copy the text of the crash and email it to helpdesk@bigideasoft.com. Error: " + e.ToString());
       }
This used to write to a crash log in a folder I designated like so:

Code: Select all

using System;
using System.IO;

namespace Anesthesia {
	internal class Logging {
		public static string LogDirectory="AnesthLogs";

		internal static void LogException(Exception e) {
			string errorText = @"\r\n" + @"\r\n"+
				"Error Message: " +e.Message+"\r\nStack Trace:\r\n"+e.StackTrace+"\r\nTime of Occurrence: "+DateTime.Now
				+"\r\n-----------------------------------------------------------------------------------------\r\n";
			try {
				if(!Directory.Exists(LogDirectory)) {
					Directory.CreateDirectory(LogDirectory);
				}
				string path=LogDirectory+"//"+DateTime.Today.ToString("MM-dd-yyyy")+".log";
				File.AppendAllText(path,errorText);
			}
			catch {
				//Do nothing
			}
		}
	}
}
But it no longer seems to be working, i.e., when there is a crash the user only sees the OD crash message, and nothing is written to my crash logs like it used to be.

Did something change in the OD code for handling crashes recently?
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

User avatar
jsalmon
Posts: 1596
Joined: Tue Nov 30, 2010 12:33 pm
Contact:

Re: Plugin crash log no longer working

Post by jsalmon » Fri Jul 26, 2024 10:06 am

I remember having trouble catching some exceptions when I wrote the HookException() paradigm. It's why I wrote this gnarly summary on the virtual method down in PluginBase:

Code: Select all

///<summary>This method will get called if there is an exception when this plugin has an exception thrown.
///This will allow the 3rd party developer to handle unexpected exceptions however they deem fit.
///Most common exceptions that will get here are due to the office updating to a version that the plugin does not currently support.
///Side note: this method will NOT get called if an exception throws within a complicated plugin.
///Complicated plugins are ones that leave the "main thread".  E.g. timers, new forms spawned via .Show() instead of .ShowDialog(), etc.</summary>
public virtual void HookException(Exception e) {
		
}
What I can tell you is that I successfully displayed the the following "Patient Select UE" when I tested it out in master just now:

Code: Select all

using OpenDentBusiness;
using System;
using System.Windows.Forms;

namespace PluginHelloWorld {
	public class Plugin : PluginBase {

		public override bool HookAddCode(object sender,string hookName,params object[] parameters) {
			switch(hookName) {
				case "FormOpenDental.Load_end":
					MessageBox.Show("Hello World!");
					return true;
				case "FormOpenDental.OnPatient_Click_end":
					throw new Exception("Patient Select UE");
				default:
					return false;
			}
		}

		public override void HookException(Exception e) {
			MessageBox.Show($"ERROR: {e.Message}");
		}

	}
}
The best thing about a boolean is even if you are wrong, you are only off by a bit.

Jason Salmon
Open Dental Software
http://www.opendental.com

User avatar
jsalmon
Posts: 1596
Joined: Tue Nov 30, 2010 12:33 pm
Contact:

Re: Plugin crash log no longer working

Post by jsalmon » Fri Jul 26, 2024 10:10 am

Oh, you mentioned that the user is getting the message but just no log. Probably just file I/O problems. Odds are they are falling into your catch block which just has a "do nothing" comment. Maybe do something there so you can tell if they are falling into that block of code?
The best thing about a boolean is even if you are wrong, you are only off by a bit.

Jason Salmon
Open Dental Software
http://www.opendental.com

User avatar
wjstarck
Posts: 945
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Plugin crash log no longer working

Post by wjstarck » Fri Jul 26, 2024 12:37 pm

Thanks Jason I'll give that a try
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

Post Reply