好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

c#快速写本地日志方法

很多人的程序在本地运行是好的,但是发布在服务器上后就会有各种各样的问题,但是服务器上又不能直接调试,所以直接读写本地日志成为解决问题的关键,我这个方法,会在发布网站的根目录自动创建 log.txt,并且会自动拼接日志信息。

日志可在如下找到:

代码如下:

1、引用

?

using system;

using system.io;

using system.text;

2、具体方法:

?

public static void writelog(string msg)

   {

    streamwriter stream;

    //写入日志内容

    string path = appdomain.currentdomain.basedirectory;

    //检查上传的物理路径是否存在,不存在则创建

    if (!directory.exists(path))

    {

     directory.createdirectory(path);

    }

    stream = new streamwriter(path + "\\log.txt", true, encoding.default);

    stream.write(datetime.now.tostring() + ":" + msg);

    stream.write("\r\n");

    stream.flush();

    stream.close();

   }

以上这篇c#快速写本地日志方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:http://HdhCmsTestcnblogs测试数据/highest/p/8257322.html

dy("nrwz");

查看更多关于c#快速写本地日志方法的详细内容...

  阅读:43次