Search code examples
wcfworkflowlog4networkflow-foundation-4xamlx

How to configure Log4net for WCF Workflow Service


I have a very simple WCF Workflow Service project with just 1 xamlx in it. XAMLX is also very simple with one receive receive activity and then calling an other xaml workflow.

Here is xamlx service:

enter image description here

My question is how can I configure Log4net in my xamlx service so that all the unhandled errors generated by subsequent Workflow can be logged to Event Log?


Solution

  • As I couldn't find any method which automatically logs all the unhandled errors. I have solved my problem by adding Try/Catch activity and adding some code activities to log the error.

    To configure the Logger I added this [assembly: log4net.Config.XmlConfigurator(Watch = true)] to assembly.cs and then created 2 code activities.

    One to get the logger:

      ILog logger = LogManager.GetLogger("LogName");
      return logger;
    

    Second to Log the error:

      logger.Get(context).Error(ex.Get(context));
    

    My Updated xamlx looks like below:

    enter image description here

    If anyone have any other better option, then please let me know. Thanks