AsyncWcfLib has a tracing system using the following classes:
WcfTrc: Static methods used by the library to trace program errors and program flow.
WcfTrcPluginDefault:
The plugin is activated when calling WcfTrc.UsePlugin (new WcfTrcPluginDefault());
Your application may call WcfTrc.StartAppInstance() on program start to set the ApplicationInstance.
The plugin just writes to System.Diagnostics.Trace. This traceoutput goes to VisualStudios output window.
You may add a tracing system of your own joice to System.Diagnostics.Trace.Listeners or you may use another plugin.
WcfTrcPluginDefault also contains utility methods to handle general application exceptions.
WcfTrcPluginFile: This plugin (or your own class implementing ITracePlugin) may be used instead of WcfTrcPluginDefault.
The plugin is activated when calling WcfTrc.UsePlugin (new WcfTrcPluginFile());
It writes your trace output to a file.
Your application should call WcfTrc.StartAppInstance() on program start and WcfTrc.Stop() during shutdown.
Call WcfTrc.Run() every few seconds. This flushes the filebuffer to disk and you can read the latest trace message with a text viewer.
After writing 2MB to trace, the file is renamed to ..old and a new file is started. This way you get at least 2MB and at most 4MB of tracing information.
UnitTest.Log4NetAdapter: This demonstrates a plugin redirecting AsyncWcfLib trace to a log4net 'appender'.
ActorInput and ActorOutput objects have a 'Logger' property. This is used to set e.g. a log4net logger used for this actor.
You may plug in your own implementation of WcfTrc.ITracePlugin.
Starting and stopping trace:
When you do not call WcfTrc.UsePlugin(...) no trace is written.
The default implementation of WcfDefault.StartAppInstance reads the first commandlineparameter as the ApplicationInstance number.
Adapt WcfDefault.StartAppInstance() to your own needs. For this purpose it is recommended to subclass WcfDefault.cs and plug in your own implemantation: WcfDefault.Instance = new MyWcfDefaults();
Example:
static void Main (string[] args) { WcfTrc.UsePlugin (new WcfTrc.PluginDefault()); WcfDefault.StartAppInstance (args); ... run application ... WcfTrc.Stop(); }
Trace messages written by the WcfTrcPlugins consist of the following fields:
A mark to symbolize gravity of the message:
## for errors or exceptions, written by WcfTrc.Error(...) or WcfTrc.Exception(...)
!! for warnings, written by WcfTrc.Warning(...)
.. for normal program flow, written by WcfTrc.Info(...)
Date/time stamp. Date may be switched off (see WcfTrcPlugin.DisplayDate)
A group field used for object names and message flow indication. WcfMessage has properties intended to use on this field:
CltSndId, CltRcvId, SvcRcvId and SvcSndId: Marking the message on client and service side, indicating receiving or sending direction.
A text field for free application use.