using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.IO; using System.Text; using System.Activities.Presentation.Metadata; namespace errorcapturing { public class ErrorHandle { private static String ErrorlineNo, Errormsg, extype, ErrorLocation; public static void SendErrorToText(Exception ex) { var line = Environment.NewLine + Environment.NewLine; ErrorlineNo = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7); Errormsg = ex.GetType().Name.ToString(); extype = ex.GetType().ToString(); ErrorLocation = ex.Message.ToString(); try { string filepath = "c:\\LogError\\"; //Text File Path if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } filepath = filepath + "ProgramLog" + " " + DateTime.Today.ToString("yyyy-MM-dd") + "." + "txt"; //Text File Name if (!File.Exists(filepath)) { File.Create(filepath).Dispose(); } using (StreamWriter sw = File.AppendText(filepath)) { string error = "Log Written Date:" + " " + DateTime.Now.ToString() + line + "Error Line No :" + " " + ErrorlineNo + line + "Error Message:" + " " + Errormsg + line + "Exception Type:" + " " + extype + line + "Error Location :" + " " + ErrorLocation + line; sw.WriteLine("-----------Exception Details on " + " " + DateTime.Now.ToString() + "-----------------"); sw.WriteLine("-------------------------------------------------------------------------------------"); sw.WriteLine(line); sw.WriteLine(error); sw.WriteLine("--------------------------------*End*------------------------------------------"); sw.WriteLine(line); sw.Flush(); sw.Close(); } } catch (Exception e) { e.ToString(); } } } // Declare dummy register metadata class to force UiPath to load this assembly public class RegisterMetadata : IRegisterMetadata { public void Register() { } } }