Create and Log to a File (in customization)

I have a customization that I currently debug using statements like this:


EpiMessageBox.Show(String.Format(" A Part Rev EXISTS for Material '{0}' on Company '{1}' .", row["MtlPartNum"].ToString(), revisionCompany));

Can I use some sort of logging library for c# or is there something Epicor provides? (I don’t want to display anything to the user)

use below code, this writes to the server log:


string msg =" Test Log Message";
Ice.Diagnostics.Log.WriteEntry(msg); 

note :- this code applicable for BPM

2 Likes

Is there anyway to write to a remote directory other than defaulting into the server log?

Use this

3 Likes

this will work with customization?

1 Like

ah no this is server side.

1 Like

And vote for this:

Logging to the application server? Pfft. There are a lot of great logging tools (one that Epicor is actually using) that will log to multiple targets - including :cloud: where you can set triggers to notify you of issues proactively.

2 Likes

Does telemetry come from the client side? :thinking: Just wondering if there’s another way…

1 Like

Presumably you can write to any file location accessible to both you and the user using standard C# code?

Otherwise, if it’s just while you’re working on it and you want to avoid annoying users, I tend to add a couple of Script-level variables like

bool debug;
string debuguser;

Then prefix the MessageBox calls with a check to whether debugging is on and it’s me running the form. It’s crude, but the immediate feedback is usually what I need and it saves clogging up drives with text files.

1 Like

Personally

I would not write to a log file from a Customization. Because a Customization runs on the Client and under the users Windows Account, the user is at the mercy of having access and permissions to the Path you want to log to. If you can assure Terminal Users and non Local-Admins etc all have access good.

Also you will need to setup a Setting so you can read where to log to, you dont want to hard-code the Path. So maybe on Company Maintenance add a field called Company_UD.ClientSideLogPath_c – You can read the folder from the Agent Settings too, but typically in your Env they have a specific Folder they want to target.

but if you must then its just basic C# – theres no helper for client… C# StreamWriter Examples - Dot Net Perls

Client = Runs as users windows account… BPM = Runs as Server Service Account (executes server-side).

PS you could also write to Event Log if you need for Debugging Purposes:

Ice.Lib.Framework.EventLog.Current.WriteEntry("Hello World");
Ice.Lib.Framework.EventLog.Current.WriteEntry("Hello World", EventLogEntryType.Error);
Ice.Lib.Framework.EventLog.Current.WriteEntry("Hello World", EventLogEntryType.Warning); 
4 Likes

@bradberkobien you could also enclose the messagebox in an if statement to only display for your account or if the account belongs to a specific security group, if only needed to debug. Better idea to debug is create a copy of the current customization and debug that one if other users are accessing the customization. Better yet, use Visual Studio to debug…

Another thing that some people do, to indicate merely a “Progress Log” is they place a Large Multi-Line Textbox on the Form and simply keep writing to that, so the user can review it. (Looks at @Chris_Conn MAK V5)

1 Like

Yep, and if I might suggest, do custom line insertions so the log goes top down instead of bottom up.

How can I log to this part of the screen within a customization. (want to show progress)

1 Like
// Status Text: Ready
this.oTrans.PushStatusText("Cat.."); // Status Text: Cat...
this.oTrans.PushStatusText("Mouse.."); // Status Text: Mouse...
this.oTrans.PopStatus(); // Status Text: Cat...
this.oTrans.PopStatus(); // Status Text: Ready
3 Likes

Have anybody tried to push status text from BPM, please let me know

That is what I use.

I save text on the server…

using(System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Temp\" + res + "_Directive_TraceMaintReq.log", true)) //my file is on server, under c:\temp
{
	bool log = true;
	//I use a var so at the end the logging, it  can stay, just put log to false...
	if(log)
		{
			file.WriteLine("");
			file.WriteLine(string.Format("BPM MaintReq (CaptureContextInfo)  Date {0} by {1}", DateTime.Now, callContextClient.CurrentUserId));
		}

//your directive code


}

Hope this helps

Pierre

2 Likes