public static void LogToFile <T> (string result) { var stackTrace = new StackTrace(); var name = typeof(T).FullName; var date = DateTime.Now.ToString("hh:mm:ss MM/dd/YYYY"); string methodCaller = stackTrace.GetFrame(1).GetMethod().Name; // Get calling method name if (methodCaller.Contains("LogToFile")) { methodCaller = stackTrace.GetFrame(2).GetMethod().Name; } System.IO.File.AppendAllText ( UtilHelper.GetFilePath("output.txt"), $"\n\n\n\nFileName: {name}.{methodCaller} at time: {date}\n{result}" ); }