Logging in a Custom Service Tutorial (Coded Workflows)

Hello,

If you are like me, you might be using Coded Workflows because you value the automation power the platform brings, but you prefer to organize your projects in a way that is more similar to traditional application software.

UiPath allows you to register reuseable custom services via dependency injection, which is detailed in this documentation:
Studio - Registering custom services

However, there is one problem, by default, Code Source files have no means of logging to Orchestrator. This is unlike Coded Workflows which inherit the ability to this from their base class. So here is a quick guide on how to log in your custom services. If you are familiar with .NET Core application development, you will find it is very similar to how it is done there.

  1. Add logger service as an argument in the constructor of your custom service within the code source file. I also added ISystemService so I can get assets from Orchestrator easily in the constructor.
public HttpClientService(IOutputLoggerService loggerService, ISystemService sysService)
        {
            logger = loggerService;
            system = sysService;
        }
  1. Register in your Coded Workflow Partial Class
public partial class CodedWorkflow : CodedWorkflowBase
    {
        public IHttpClientService httpClientService { get => serviceContainer.Resolve<IHttpClientService>(); }
        
        protected override void RegisterServices(ICodedWorkflowsServiceLocator serviceLocator)
		{
            serviceLocator.RegisterType<IHttpClientService, HttpClientService>(CodeServiceRegistrationType.Singleton);
		}
    }

And just like that you can now log in your custom service. Hope someone finds this helpful.

3 Likes

Hello @edevries!

It seems that you have trouble getting an answer to your question in the first 24 hours.
Let us give you a few hints and helpful links.

First, make sure you browsed through our Forum FAQ Beginner’s Guide. It will teach you what should be included in your topic.

You can check out some of our resources directly, see below:

  1. Always search first. It is the best way to quickly find your answer. Check out the image icon for that.
    Clicking the options button will let you set more specific topic search filters, i.e. only the ones with a solution.

  2. Topic that contains most common solutions with example project files can be found here.

  3. Read our official documentation where you can find a lot of information and instructions about each of our products:

  4. Watch the videos on our official YouTube channel for more visual tutorials.

Hopefully this will let you easily find the solution/information you need. Once you have it, we would be happy if you could share your findings here and mark it as a solution. This will help other users find it in the future.

Thank you for helping us build our UiPath Community!

Cheers from your friendly
Forum_Staff

I am not, there just is not a good forum post option for sharing information

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.