public class FileSupport
{
public static FileSupport Instance = new FileSupport();
public static string mRoot =Environment.CurrentDirectory+"/log"; public string mPath = Environment.CurrentDirectory + "/log/" + System.DateTime.Now.ToString("yyyy-MM-dd") + ".txt"; public bool FileExit()
{
if (!Directory.Exists(mRoot))//如果不存在就创建file文件夹
{
Directory.CreateDirectory(mRoot);
}
if (!File.Exists(mPath))
{
return false;
}
return true;
} public void Write(string msg)
{
FileStream fs;
if(!FileExit())
{
fs= File.Create(mPath);//创建该文件
}
else
{
fs = new FileStream(mPath, FileMode.Append);
} StreamWriter sw = new StreamWriter(fs);
//开始写入
var addstr = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " "+msg + "\r\n";
sw.Write(addstr);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
} }

.net 文件接口的封装,写日志,创建文件log的更多相关文章

  1. C# 写日志到文件

    C# 写日志到文件 using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms ...

  2. 【m从翻译os文章】写日志禁令Sqlnet.log和Listener.log

    写日志禁令Sqlnet.log和Listener.log 参考原始: How to Disable Logging to the Sqlnet.log and the Listener.log (Do ...

  3. 判断文件是否存在,不存在创建文件&&判断文件夹是否存在,不存在创建文件夹

    1.判断文件是否存在,不存在创建文件 File file=new File("C:\\Users\\QPING\\Desktop\\JavaScript\\2.htm"); if( ...

  4. Linux课程---5、常用文件命令和目录命令(创建文件命令)

    Linux课程---5.常用文件命令和目录命令(创建文件命令) 一.总结 一句话总结: touch file1 1.管道符|有什么用? 将前一个命令的结果作为后一个命令的输入:比如查看文件前3行:ca ...

  5. File IO(NIO.2):读、写并创建文件

    简介 本页讨论读,写,创建和打开文件的细节.有各种各样的文件I / O方法可供选择.为了帮助理解API,下图以复杂性排列文件I / O方法 在图的最左侧是实用程序方法readAllBytes,read ...

  6. jmert中如何测试上传文件接口(测试上传excel文件)

    第一次用jmeter这个工具测试上传接口,以前没做过这一块,导致走了很多弯路.特地把经验谢谢,怕自己以后忘记... 一,jmeter如何上传文件 jmeter 的 http requests post ...

  7. 小程序请求接口统一封装到一个js文件中

    在我们做小程序时,数据请求数据请求是避免不了的,然而我们用官方自带的请求方式,会给我们带来很多重复的工作,所以我就借鉴大神们的博客,写了一个简单的请求方式. 1.首先我们在utils中新建一个api. ...

  8. primary库新增数据文件后,standby库无法创建文件并终止数据同步

    主库是RAC环境,使用asm存放数据文件,备库是操作系统本地文件系统存放数据文件.在主库执行以下操作: SQL> alter tablespace ysdv add datafile '+dat ...

  9. 快速php日志,写内容到文件,把日志写到log文件

    php 写内容到文件,把日志写到log文件 //记录日志:要写入文件的文件名(可以是任意文件名),如果文件不存在,将会创建一个.log.txt位置在项目的根目录下. $file = 'log.txt' ...

随机推荐

  1. Python中关于日期的计算总结

    1.获取当前时间的两种方法: 代码如下: import datetime,timenow = time.strftime("%Y-%m-%d %H:%M:%S")print now ...

  2. Vmvare扩展虚拟机磁盘大小

    Vmvare设置好虚拟机的磁盘大小之后,发现磁盘空间不够了,这个时候怎么扩展磁盘的大小呢? 首先,在确保虚拟机关闭的情况下,右键设置,选择硬盘,扩展,这样就可以增加磁盘的大小. 但是由于未进行分区和磁 ...

  3. 剑指offer-面试题40-最小的k个数-最大堆

    /* 题目: 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. */ /* 思路: 利用最大堆,C++中使用multiset& ...

  4. Vue项目中实现tab栏和步骤条的数据联动

    也就是tab栏切换步骤条随之变化 <template>   <div>     <!-- 面包屑导航  -->     <el-breadcrumb sepa ...

  5. JavaScript-跨浏览器事件处理程序(EventUtil)

    事件操作对象: var EventUtil= { //添加事件 addHandler: function (element, type, handler) { if (element.addEvent ...

  6. Yarn报错:Exception message: /bin/bash: line 0: fg: no job control

    Exception message: /bin/bash: line 0: fg: no job control 这个错误是 本地idea跨平台远程调试hadoop集群出现的,在使用windows调用 ...

  7. HDU6683

    题意 英文 做法 考虑公比为\(\frac{a}{b}\),满足\(a>b,(a,b)=1\) 枚举长度\(k\),设序列头为\(p\),尾为\(q\),有\(p\times \frac{a^{ ...

  8. Constructing Roads POJ - 2421 最小生成树板子题

    #include<iostream> #include<cstring> #include<algorithm> using namespace std; ; in ...

  9. install multiple versions of CUDA

    https://www.pugetsystems.com/labs/hpc/How-To-Install-CUDA-10-together-with-9-2-on-Ubuntu-18-04-with- ...

  10. Hdu1042 N! (阶乘高精度模板)

    Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!   Input One N in ...