writing text in error log note pad

Last Reply 8 days ago By pandeyism

Posted 8 days ago

friends how to set path to wite success messange in notepad in console application?

its showing issu that path not found.

                            if (Convert.ToInt32(response1.StatusCode) == 200)
                            {
                                string message = string.Format("Time: {0}", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"));
                                message += Environment.NewLine;
                                message += "-----------------------------------------------------------";
                                message += Environment.NewLine;
                                message += string.Format("Message: {0}", response1.StatusCode);
                                message += Environment.NewLine;
                                message += "-----------------------------------------------------------";
                                message += Environment.NewLine;
                                using (StreamWriter writer = new StreamWriter("\\ErrorLog\\Success.txt", true))
                                {
                                    writer.WriteLine(message);
                                    writer.Close();
                                }
                            }
Posted 8 days ago Modified on 7 days ago

Hi sureshMGR,

Since its a console application you can't use Server.MapPath.

For for console application you will get the path using AppDomain.CurrentDomain.BaseDirectory.

From the path get the application path and write the error log in notepad.

C#

if (Convert.ToInt32(response1.StatusCode) == 200)
{
    string message = string.Format("Time: {0}", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"));
    message += Environment.NewLine;
    message += "-----------------------------------------------------------";
    message += Environment.NewLine;
    message += string.Format("Message: {0}", response1.StatusCode);
    message += Environment.NewLine;
    message += "-----------------------------------------------------------";
    message += Environment.NewLine;
    string path = AppDomain.CurrentDomain.BaseDirectory.Replace("bin\\Debug\\", "") + "\\ErrorLog";
    if (!Directory.Exists(path))
    {
        Directory.CreateDirectory(path);
    }
    using (StreamWriter writer = new StreamWriter(path + "\\Success.txt", true))
    {
        writer.WriteLine(message);
        writer.Close();
    }
}

 

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html