这些语句 我觉得没问题啊 为什么没有记录呢?我在自己的电脑上测试的时候没有任何记录在sqlin.txt中,想写入记入 应该怎么写呢?string clientIp = System.Web.HttpContext.Current.Request.UserHostAddress.ToString();// WbfTools.BLL.Utils.GetIP();
                        string clientURL = System.Web.HttpContext.Current.Request.Url.ToString();
                        string serverParch = System.Web.HttpContext.Current.Server.MapPath("~/");
                        //写日志
                        System.IO.StreamWriter sw = System.IO.File.AppendText(serverParch + "\\sqlin.txt");//System.Net.WebRequestMethods.File.AppendText(serverParch + "\\sqlin.txt");
                        sw.WriteLine("IP:" + clientIp + "   URL:" + clientURL + "   DateTime:" + DateTime.Now.ToString());
                        sw.Flush();
                        sw.Close();
                        sw.Dispose();

解决方案 »

  1.   

    调试一下。txt文件不存在的时候先创建一个文件。
      

  2.   

    路径没问题 txt已经存在啊,我现在在想 不会自己攻击自己没有记录吧???
      

  3.   

    用Server.MapPath(".")代替一下试试
      

  4.   

    调试下不过在正式环境这样写肯定是不行,要考虑并发。
    现在记录日志有log4net、nlog之类的,也有自己写的直接写文件的方法(一般用多线程)。
      

  5.   

    调试信息:
    - sw {System.IO.StreamWriter} System.IO.StreamWriter
    - base {System.IO.StreamWriter} System.IO.TextWriter {System.IO.StreamWriter}
    - base {System.IO.StreamWriter} System.MarshalByRefObject {System.IO.StreamWriter}
    - 非公共成员
    - [System.IO.StreamWriter] {System.IO.StreamWriter} System.IO.StreamWriter
    - base {System.IO.StreamWriter} System.IO.TextWriter {System.IO.StreamWriter}
    - base {System.IO.StreamWriter} System.MarshalByRefObject {System.IO.StreamWriter}
    __identity null object
    Identity null object
    - CoreNewLine {char[2]} char[]
    [0] 13 '\r' char
    [1] 10 '\n' char
    InternalFormatProvider null System.IFormatProvider
    autoFlush false bool
    + byteBuffer {byte[3075]} byte[]
    + charBuffer {char[1024]} char[]
    charLen 1024 int
    charPos 0 int
    Closable true bool
    closable true bool
    + encoder {System.Text.UTF8Encoding.UTF8Encoder} System.Text.Encoder {System.Text.UTF8Encoding.UTF8Encoder}
    + encoding {System.Text.UTF8Encoding} System.Text.Encoding {System.Text.UTF8Encoding}
    haveWrittenPreamble true bool
    + mdaHelper {System.IO.MdaHelper} System.IO.MdaHelper
    + stream {System.IO.FileStream} System.IO.Stream {System.IO.FileStream}
    __identity null object
    Identity null object
    + Encoding {System.Text.UTF8Encoding} System.Text.Encoding {System.Text.UTF8Encoding}
    + FormatProvider {zh-CN} System.IFormatProvider {System.Globalization.CultureInfo}
    NewLine "\r\n" string
    + 静态成员
    + 非公共成员
    AutoFlush false bool
    + BaseStream {System.IO.FileStream} System.IO.Stream {System.IO.FileStream}
    + Encoding {System.Text.UTF8Encoding} System.Text.Encoding {System.Text.UTF8Encoding}
    + 静态成员
    + 非公共成员
      

  6.   

    有个异常 信息:
    正在中止线程
    这是怎么回事?
    但是页面上还是有显示try中的值