Skip to main content

Error Log - Error Writer to Text File.

public static void ErrorWriter(string Message, string InnerException, string StackTrace, string FileName, string MethodName)
        {

            try
            {
                string path = "path";
                // This text is added only once to the file.
                // Write to the file:
                if (File.Exists(path) && (new FileInfo(path)).Length > 5 * 1024 * 1024)
                {
                    File.Move(path, path.Replace(".txt", DateTime.Now.Ticks.ToString() + ".txt"));
                }

                string log = string.Empty;
                log += "=============================================================================";
                log += Environment.NewLine.ToString();               
                log += "Data Time:" + DateTime.Now;
                log += Environment.NewLine.ToString();
                log += "Message:" + Message;
                log += Environment.NewLine.ToString();
                log += "InnerException:" + InnerException;
                log += Environment.NewLine.ToString();
                log += "StackTrace:" + StackTrace;
                log += Environment.NewLine.ToString();
                log += "File Name:" + FileName;
                log += Environment.NewLine.ToString();
                log += "Method Name:" + MethodName;
                log += Environment.NewLine.ToString();
                File.AppendAllText(path, log);

            }
            catch (Exception)
            {

            }


        }

Comments

Popular posts from this blog

Tata Punch: A Compact SUV That Packs a Punch

Pass Values Between ASP.NET Web Pages without Session or any State Management

If the source page and target page are both ASP.NET Web pages in the same Web application, and if you transfer execution from the source page to the target page on the server by using the transfer method, the target page can access public properties in the source page. Page One <asp:TextBox ID="textCity" runat="server" Text="Brjesh"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />  public String CurrentCity         {             get             {                 return textCity.Text;             }         }         public List<String> Current    ...

Message Helper for MVC Application

Message Helper for MVC Application public static class MessageExtensions { public enum MessageType { Success = 0, Info = 1, Warning = 2, Error = 3 } public static void ShowMessage( this Controller controller, MessageType messageType, string message, bool showAfterRedirect = false ) { string messageTypeKey = messageType.ToString(); if (showAfterRedirect) { controller.TempData[messageTypeKey] = message; } else { controller.ViewData[messageTypeKey] = message; } } public static HtmlString RenderMessages( this HtmlHelper htmlHelper, bool clearMessage = true ) { string messages = String .Empty; foreach ( string messageType in Enum .GetNames( t...