zoukankan      html  css  js  c++  java
  • 获取站点路径方法

    /// <summary>
            
    /// 保存程序失败及错误信息到日志
            
    /// </summary>
            
    /// <param name="opLog">错误信息</param>

            public void SaveErrorLog(string message)
            
    {
                
    string filePath = System.Web.HttpContext.Current.Server.MapPath("~//LogFile//Test.txt");
                System.IO.StreamWriter srWriteLine 
    = System.IO.File.CreateText(filePath); 
                srWriteLine.WriteLine(message); 
                srWriteLine.Close(); 
            }

    当前站点是:http://localhost/App/Web

            /// <summary>
            
    /// 保存程序失败及错误信息到日志
            
    /// </summary>
            
    /// <param name="opLog">错误信息</param>

            public void SaveErrorLog(string message)
            
    {
                
    string fileName = System.DateTime.Today.Year.ToString() + "-" + System.DateTime.Today.Month.ToString() + "-" + System.DateTime.Today.Day.ToString() + ".txt";
                
    string filePath = System.Web.HttpContext.Current.Server.MapPath("~//LogFile//"+fileName);
                
    if (!System.IO.File.Exists(filePath))
                
    {
                    System.IO.StreamWriter srWriteLine 
    = System.IO.File.CreateText(filePath); 
                    srWriteLine.WriteLine(message); 
                    srWriteLine.Close(); 
                }
                
                
    else
                
    {
                    FileStream fsMyfile 
    = new FileStream(filePath,FileMode.Append, FileAccess.Write);
                    StreamWriter swMyfile 
    = new StreamWriter(fsMyfile); 
                    swMyfile.WriteLine(message); 
                    swMyfile.Flush(); 
                    swMyfile.Close(); 
                    fsMyfile.Close(); 
                }

            }
  • 相关阅读:
    【POJ】【2420】A Star not a Tree?
    【BZOJ】【2818】Gcd
    【BZOJ】【2190】【SDOI2008】仪仗队
    【Vijos】【1164】曹冲养猪
    【BZOJ】【1430】小猴打架
    【BZOJ】【3611】【HEOI2014】大工程
    【转载】完全图的生成树
    【BZOJ】【2286】【SDOI2011】消耗战
    【POJ】【1061】/【BZOJ】【1477】青蛙的约会
    Codeforces VK Cup Finals #424 Div.1 A. Office Keys(DP)
  • 原文地址:https://www.cnblogs.com/adam/p/668253.html
Copyright © 2011-2022 走看看