Page 1 of 1

Plugin crash log no longer working

Posted: Fri Jul 26, 2024 6:42 am
by wjstarck
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?

Re: Plugin crash log no longer working

Posted: Fri Jul 26, 2024 10:06 am
by jsalmon
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}");
		}

	}
}

Re: Plugin crash log no longer working

Posted: Fri Jul 26, 2024 10:10 am
by jsalmon
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?

Re: Plugin crash log no longer working

Posted: Fri Jul 26, 2024 12:37 pm
by wjstarck
Thanks Jason I'll give that a try