简体   繁体   中英

New log file every time we uploaded new binaries

We would like to add some "start code" to indicate log file for every time we update ASP.NET site's binaries. So, for instance, we have binaries ver.1.0, and log writes to log_JhdsgGd1.txt. Next time we correct some bugs and then uploaded new binaries ver.1.1. And now, we want log file writes to some other log_h12jh3G.txt. We don't change any version number in project.

I have tried generate some start code once at Application_Start() and then use it in class that writes log. But unfortunately it doesn't work as supposed to be.


POST UPDATE

protected void Application_Start()
{
    Random r = new Random();
    Application["startCode"] = r.Next(100000).ToString();

    AreaRegistration.RegisterAllAreas();
    RegisterRoutes(RouteTable.Routes);
}

public static class Logger
{
    static internal void WriteLog(string msg, string dbname = null)
    {
        using (StreamWriter sw = new StreamWriter(String.Format("{0}{1}{2}", HttpContext.Current.Server.MapPath("log"), Path.DirectorySeparatorChar, String.Format("log_{0}.txt", HttpContext.Current.Application["startCode"]), true)))
        {
            string logEntry;
            if (!String.IsNullOrEmpty(dbname))
                logEntry = String.Format("{0} ({1}): {2}", DateTime.Now.ToString(), dbname, msg);
            else
                logEntry = String.Format("{0}: {1}", DateTime.Now.ToString(), msg);

            sw.WriteLine(logEntry);
            sw.WriteLine("------------");
            sw.Flush();
            sw.Close();
        }
    }
}

Could you link SVN/GIT revision to your project? Or calculate MD5 of your binary file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM