/// <summary>
        ///
        /// </summary>
        /// <param name="serverObjects"></param>
        public void LogToFile(DeviceServerObjects serverObjects, bool useInstallLocation, out Exception exception)
        {
            exception = null;
            try
            {
                string location = useInstallLocation ? RegistryTools.GetInstallLocationByDisplayName(
                    Static.MattimonRegistrySubkeyNames.DisplayName) + "\\" : "";

                FileStream rfs = new FileStream(location + serverObjects.GetType().Name + "." +
                                                (serverObjects.PostAction ?? "LocalRequest") + ".log",
                                                FileMode.OpenOrCreate, FileAccess.Read);
                StreamReader sr      = new StreamReader(rfs);
                bool         hasData = sr.ReadLine() != null;
                sr.Close();
                rfs.Close();

                FileStream wfs = new FileStream(location + serverObjects.GetType().Name + "." +
                                                (serverObjects.PostAction ?? "LocalRequest") + ".log",
                                                FileMode.Append, FileAccess.Write);
                StreamWriter sw = new StreamWriter(wfs);

                if (hasData)
                {
                    sw.WriteLine();
                    sw.WriteLine();
                    sr.Close();
                    rfs.Close();
                }

                sw.WriteLine("[{0}]", DateTime.Now);

                foreach (ServerInstance si in serverObjects.Instances)
                {
                    sw.WriteLine("[INSTANCE]");
                    sw.WriteLine("  WEBID: " + (si.ID == 0 ? "n/a" : si.ID.ToString()));
                    sw.WriteLine("  Server name: " + si.ServerName);
                    sw.WriteLine("  Instance name: " + (si.InstanceName == "" || si.InstanceName == null ? "DEFAULT" : si.InstanceName));
                    sw.WriteLine("  Last Reported: " + (si.LastReportedTimestamp <= 0 ? "Never" : DateUtils.UnixTimeStampToDateTime(si.LastReportedTimestamp).ToString()));

                    foreach (Database db in si.Databases)
                    {
                        sw.WriteLine("  [DATABASE]");
                        sw.WriteLine("    WEBID: " + (db.ID == 0 ? "n/a" : db.ID.ToString()));
                        sw.WriteLine("    Name: " + db.DatabaseName);
                        sw.WriteLine("  [/DATABASE]");

                        foreach (DatabaseConnectionInfo ci in db.Connections)
                        {
                            sw.WriteLine("   [CONNECTION]");
                            sw.WriteLine("     WEBID: " + (ci.ID == 0 ? "n/a" : ci.ID.ToString()));
                            sw.WriteLine("     Host: " + ci.Hostname);
                            sw.WriteLine("     Program: " + ci.ProgramName);
                            sw.WriteLine("   [/CONNECTION]");
                        }
                    }
                    sw.WriteLine("[/INSTANCE]");
                    sw.WriteLine();
                    sw.WriteLine();
                    sw.WriteLine();
                }
                sw.Close();
                wfs.Close();
            }
            catch (Exception ex) { exception = ex; }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="instances"></param>
        private void DeleteSqlServerInstance(ServerInstance[] instances)
        {
            string svcPath = string.Empty, svcName = string.Empty;

            FormBackgroundWorker deleteInstances = new FormBackgroundWorker(this,

                                                                            new DoWorkEventHandler((s, e) => {
                SQLServerRequests requests = new SQLServerRequests();

                DeviceServerObjects dso = new DeviceServerObjects();

                dso.DeviceID = GetDeviceID();

                dso.Instances = instances;

                try
                {
                    svcPath = Path.Combine(RegistryTools.GetInstallLocationByDisplayName(

                                               MattimonAgentLibrary.Static.MattimonRegistrySubkeyNames.DisplayName),

                                           "MattimonSQLServerService.exe");

                    if (!File.Exists(svcPath))
                    {
                        throw new IOException("Could not locate the service file: " + svcPath + ".\n" +

                                              "Re-installing the application might fix this issue.");
                    }
                }

                catch (IOException ioe) { throw ioe; }

                catch (Exception ex) { throw ex; }

                svcName = new ProjectAssemblyAtrributes(svcPath).AssemblyTitle;

                SQLiteClientDatabase db = GetLocalDatabase();

                foreach (ServerInstance si in dso.Instances)
                {
                    string insname = si.InstanceName.ToLower().Equals("mssqlserver") ? "" : si.InstanceName;

                    db.DeleteConnectionStringEntry(si.ServerName, insname);
                }



                e.Result = requests.PostDeviceServerObjects(dso, DeviceServerObjectAction.delete);
            }), "Deleting Instance(s)");

            deleteInstances.RunWorkerCompletedEventHandler = new RunWorkerCompletedEventHandler((s, e) => {
                if (e.Error != null)
                {
                    GUI.BitscoreForms.BitscoreMessageBox.Show(this, "An error occurred while attempting to delete SQL Server instances.\n\n" +
                                                              "Error details:\n" + Tools.ExceptionHelper.GetFormatedExceptionMessage(e.Error),
                                                              "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (e.Result != null && e.Result is DeviceServerObjects dso)
                {
                    if (dso.Exception != null || dso.HttpRequestException != null)
                    {
                        if (dso.Exception != null)
                        {
                            GUI.BitscoreForms.BitscoreMessageBox.Show(this, "An server-side error occurred.\n\n" +
                                                                      "Error details:\n" + Tools.ExceptionHelper.GetFormatedExceptionMessage(dso.Exception),
                                                                      "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        if (dso.HttpRequestException != null)
                        {
                            GUI.BitscoreForms.BitscoreMessageBox.Show(this, "An server-side error occurred.\n\n" +
                                                                      "Error details:\n" + Tools.ExceptionHelper.GetFormatedExceptionMessage(dso.HttpRequestException),
                                                                      "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        return;
                    }

                    BtnSqlSrv_Refresh_Click(btn_sqlsrv_refresh, EventArgs.Empty);


                    GUI.BitscoreForms.BitscoreMessageBox.Show(this, "Instance(s) have been deleted.",
                                                              Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            });
            deleteInstances.DoWork();
        }