Unable to Add Log fields in The custom activity for Log

using System;
using System.Activities;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.IO;
using UiPath.Core.Activities;

namespace CustomLogging
{
public class CustomLogActivity : CodeActivity
{
// Methods
[Category(“Log”), RequiredArgument]
public InArgument LogCode { get; set; }
[Category(“Log”)]
public InArgument ExtraData { get; set; }
[Category(“Log”)]
public InArgument Message { get; set; }

    public CustomLogActivity()
    {
        this.ExtraData = "";
        this.Message = "";
    }
    
    protected override void Execute(CodeActivityContext context)
    {
        string machineNameValue = Environment.MachineName;
        InArgument<string> machineName = new InArgument<string>();
        machineName = machineNameValue;
        Dictionary<string, InArgument> NewFieldsDictionary = new Dictionary<string, InArgument>
        {
            { "LogCode", this.LogCode },
            { "ExtraData", this.ExtraData},
            { "MachineName", machineName }
        };
        List<InArgument<string>> NewFieldsList = new List<InArgument<string>>
        {
            "LogCode",
            "ExtraData",
            "MachineName"
        };

        
       
        AddLogFields addLog = new AddLogFields() { Fields = NewFieldsDictionary };

        WorkflowInvoker activity = new WorkflowInvoker(addLog);
       
        activity.Invoke();


        


        LogMessage customLog = new LogMessage
        {
            Level = CurentLogLevel.Info,
            Message = this.Message
        };

        activity = new WorkflowInvoker(customLog);
        activity.Invoke();
        
        RemoveLogFields removeLog = new RemoveLogFields() { Fields = NewFieldsList };
        activity = new WorkflowInvoker(removeLog);
        activity.Invoke();
        
        
    }

    

}

}

1 Like

@ovi I hope you could help me with this.
this custom activity runs without error but I dont see the additional fields in the the log message.
I am not sure why the add log fields activity not working for me.

Below is the output of Log message.
{
“message”: “test message”,
“level”: “Information”,
“timeStamp”: “12:33:14”,
“processVersion”: “1.0.6797.29120”,
“fileName”: “Main”,
“jobId”: “a5aafbf3-31de-48f3-9d79-b7e6ef8b064f”,
“robotName”: “Rohan_Laptop”
}

1 Like

Hey Rohan,

I need to investigate for your custom activity. But why don’t you use the Add log fields activity?

This is what I get when running the Add log fields activity:
13:19:47.1039 Info {
“message”:“add log fields execution ended”,
“level”:“Information”,
“logType”:“Default”,
“timeStamp”:“2018-08-29T13:19:47.1029804+03:00”,
“fingerprint”:“eee59091-0d8c-402f-9528-********”,
“windowsIdentity”:“blabla\viorela”,
“machineName”:“VIO”,
“processName”:“add log fields”,
“processVersion”:“1.0.0.0”,
“jobId”:“00890866-1c7f-4565-****-2be0052d69c4”,
“robotName”:“Forum Buddy”,
“machineId”:0,
“totalExecutionTimeInSeconds”:0,
“totalExecutionTime”:“00:00:00”,
“fileName”:“Main”,
“name”:“ovi”,
“city”:“bucharest”
}

Hi @ovi

So basically in uipath we have to use three activities to do this
Add LogFields → Log Message → Remove Log Fields

Moreover for my project requirement I am supposed to make a custom code base activity for a custom logging mechanism where I want to do the work of these three activities into a single custom activity.

Hi @ovi

Did you find anything on this ?

Thanks

I have a question Rohan, why do we need Remove Log Fields , any specific reason.

Can you share sample xaml please

Hi @rohan_garg Did you find the solution for this?

Hi @Prakshi_Tyagi,

The rollover of the Uipath Library functionality did help in this but Now I am looking out for the ways to actually get the log fields and their values using some program during runtime, instead of writing them to orchestrator using log activity.

Fields/Values required are below:-
“processName”:“add log fields”,
“processVersion”:“1.0.0.0”,
“jobId”:“00890866-1c7f-4565-****-2be0052d69c4”,
“robotName”:“Forum Buddy”
“fileName”:“Main”