How to write your own trace logs

Dang it @Chris_Conn you mentioned logging. Now I have to drag out my old trace / log writing tips.

Everyone knows you can create your own trace logs, just like Epicor right? :wink:

8 Likes

I did not know this! Can you share? :slight_smile:

The magic is :

Epicor.Hosting.Trace.ServerLog.WriteTraceMessage(
“trace://ice/mytrace”,
“TraceCategoryLabel”,
() => “Some Text”
);

such as the following on Ice.Tip.GetRows

If you have that trace flag in appserver.config:
image

It will output to your tracelog:

NOTE:
The trace writes are using a func for the message text. This allows for a ‘call back’ approach. e.g. - Don’t build up your message if the trace is not active. Amazing how that speeds up things when you have hundreds of trace.writelines all over the server and are not tracing.

7 Likes

This is gold @Bart_Elia, split into its own topic. Awesome sauce, is this documented somewhere ? (Other than right here , right now lol)

2 Likes

I know this was covered during a couple deep dive sessions at Insights starting in 2015 and included in the distributed material (Powerpoint). At that time, I never found official documentation from Epicor, but I am sure I am probably wrong.

1 Like

Talk to me after Insights.

A couple of other trace items:

Ever want to time anything? Have it done for you

Epicor.Hosting.Trace.ServerLog.WriteTimedEntry(
“trace://ice/mytrace”,
“TimedTraceLabel”,
() => DoSomethingToBeTimed(),
() => “Some Message”
);

Also log tracing in context with the rest of the server:

        try
        {
             //Do Something that goes boom
        }
        catch (Exception ex)
        {
            Epicor.Hosting.Trace.ServerLog.WriteNonOperationException(ex);
            throw ex;
        }
3 Likes

adding a tracelog SHOULD be a standard Widget in the BPM tool (Just sayin!) so that we don’t have to write C# code in a BPM made of all widgets.

6 Likes

There is so much goodness here. Thanks!

Bart - does it have to be called trace://ice/mytrace or can you create your own like trace://ice/XYZTrace

No worries. We made it plug-able - just add your own uri - so partners could leverage it. It was designed that way since day 1 so you would not need someone with magic framework fairy dust blessing a name.

BTW - Another nifty feature - the uri is wildcard friendly.

Imagine two uris:

WriteTraceMessage(“trace://ice/fw/session" …
WriteTraceMessage(“trace://ice/fw/license"…

If you set a trace in appserver.config:

< add uri=“trace://ice/fw/session” />
This gives you things traced in session

< add uri=“trace://ice/fw/license” />
This gives you things traced in license

< add uri=“trace://ice/fw” />
This gives you things traced in EVERYTHING under fw. Logically “ice/fw/*.*” if that makes sense.

@hkeric.wci the trace SHOULD allow any uri but I noted a bug yesterday that we broke some areas of complete flexibility. I know that ice/Anything works. Plug in whatever you want under ice. I have a note to have system, erp and then complete flexibility checked.

1 Like

Sorry to bring up and old thread, but can this tracing be returned to the client side trace? I’m looking through help, and you can add server tracing to the client side by added some things in the sysconfig. It looks like I can add the"stock" ones with a trace: and a profile: . I’m trying to figure out if I can get these custom traces to come through like those ones. I’ve tried adding my custom flag "trace://ice/brandon/MoveMaterialProject" to the sysconfig, as well as putting it into the “other flags” portion of the client trace. No luck on any of that.

image

2 Likes

Did you add this new trace to the server AppServer.config?

Yes I did. I don’t have a profile though. Is that needed?

image

So new traces are added to server log, but they are not sent to client?

That’s correct.

It looks like a bug, you should report it.

2 Likes