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();
}
}
}