I want to write structured log,how can i implement in this piece of code

Viewed 18
public uint LaunchProcess(string sIPAddress, string sPort)
{
    uint iPid = 0;
    try
    {
        logger.AddLog("LaunchProcess : " + sIPAddress + " " + sPort);
        object[] PlugInRunnerInfo = {
            StaticUtils.GetLocation(AgilentPluginCommonConstants.PlugInRunnerPath) + "\\" + "PlugInRunner.exe" + " " + sIPAddress + " " + sPort,
            null,
            null,
            0
        };

        //ManagementClass is a part of Windows Management Intrumentation,namespaces. One of its use is to provides access to manage applications.
        //Here this class is used to launch PlugInRunner as detached process.By setting the ManagementClass object's property 'CreateFlags' to value 0x00000008
        //we can start the PlugInRunner as detached one.
        using(var mgmtObject = new ManagementClass("Win32_Process"))
        {
            var processStartupInfo = new ManagementClass("Win32_ProcessStartup");
            processStartupInfo.Properties["CreateFlags"].Value = 0x00000008; //DETACHED_PROCESS.
            var result = mgmtObject.InvokeMethod("Create", PlugInRunnerInfo);
            if (result != null)
            {
                logger.AddLog("Process id " + Convert.ToUInt32(PlugInRunnerInfo[3]));
                iPid = Convert.ToUInt32(PlugInRunnerInfo[3]);
            }
        }
    }
    catch (Exception ex)
    {
        logger.AddLog("Exception " + ex.Message);
    }
    return iPid;
}

Above is my code, I believe i have used no structured logging with the help of Ilogger interface - how can i make it structured?

0 Answers
Related