I have a task to add logging functionality to the existing workflow based solution. There is a layered architecture : BusinessLayer->AgentLayer->StoreLayer. At the business layer there is a xaml activity which consists from a one or more agent activities. Agent activity consists from one or more store activities. Agent and Store activities are inherited from CodeActivity.
Activities are executed by
WorkflowInvoker.Invoke(activity);
My task is to log the execution of each activity. The log output. should be e.g.
BusinessActivity1 has been started at 11:00 8.2.2012
AgentActivity1 has been started at 11:01 8.2.2012
StoreActivity1 has been started at 11:02 8.2.2012
StoreActivity1 has been ended at 11:03 8.2.2012
AgentActivity1 has been ended at 11:04 8.2.2012
BusinessActivity1 has been ended at 11:05 8.2.2012
So my question is what is the best practise to log something like this. I don’t want to write the LogMessage to the each activity. I prefer the unified solution. Is there exists any clever solutions?
thanks
WF already supports a logging structure which it calls WF Tracking. You would be wise to just follow the existing infrastructure so you don’t incur any unnecessary performance overhead.
You need to look at how to incorporate
TrackingParticipants. You will need to replace theWorkflowInvoker.Invoke()withWorkflowApplication(or create an instance ofWorflowInvoker) so that you can add your customTrackingParticipantvia WF Extensions. By defining aTrackingProfileyou can restrict the tracking messages to only those which you are interested by trace level, event type, and tracking record.If you wish to log your own custom
TrackingRecords, you can derive from the baseTrackingRecord.Alternatively – you could build a wrapping custom activity as suggested by @Gabocat, but this will incur additional performance overhead that WF Tracking would not.