示例#1
0
        /// <summary>
        /// Writes error text into a Log file under the specified path
        /// </summary>
        /// <param name="message">Error String</param>
        /// <param name="filePath">for relative directry Path, use Server.MapPath() method to get a path</param>
        internal static void WriteLog(string message, string filePath)
        {
            try
            {
                string directoryPath = filePath.Remove(filePath.LastIndexOf('\\'));
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }
                try
                {
                    //If file exists then append the text , otherwise create a file and insert the text
                    if (!File.Exists(filePath))
                    {
                        File.WriteAllText(filePath, " ");
                    }
                }
                catch (Exception)
                {
                }

                ErrorLogHelper.WriteErrorInLogFile(filePath, message, String.Empty);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        public static void WriteLog(string errorMessage, string directryPath, string errorDescription = "")
        {
            string FileName = string.Empty;
            string FilePath = string.Empty;

            try
            {
                // create directory if not exists
                try
                {
                    if (!Directory.Exists(directryPath))
                    {
                        Directory.CreateDirectory(directryPath);
                    }
                }
                catch (Exception)
                {
                    throw;
                }

                // Make file Name
                FileName = ErrorLogHelper.GetFileName();

                // Make a FilePath
                FilePath = Path.Combine(directryPath, FileName) + ".txt";

                try
                {
                    //If file exists then append the text , otherwise create a file and insert the text
                    if (!File.Exists(FilePath))
                    {
                        File.WriteAllText(FilePath, " ");
                    }
                }
                catch (Exception)
                {
                }

                ErrorLogHelper.WriteErrorInLogFile(FilePath, errorMessage, errorDescription);
            }
            catch (Exception)
            {
            }
        }