写日志 log 到文件夹
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace DBUtility
{
public class FileHelper
{
public static void writeLog(string strSQL)
{
try
{
string strFileName = DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
string strPath = "d:/log/";
string strAllPath = strPath + strFileName;
if (!Directory.Exists(strPath))
{
Directory.CreateDirectory(strPath);
}
if (File.Exists(strAllPath))
{
StreamWriter sw = new StreamWriter(strAllPath, true);
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + strSQL); // 写入Hello World
sw.Close(); //关闭文件
}
else
{
FileStream fs = new FileStream(strAllPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs); // 创建写入流
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + strSQL); // 写入Hello World
sw.Close(); //关闭文件
fs.Close();
}
}
catch (Exception ex) { }
finally { }
}
}
}
Request.UserAgent, Request.UserHostAddress, Request.Browser.Browser
写日志 log 到文件夹的更多相关文章
- time模块目录下自己建立一个名为log的文件夹
使用python调用ping命令,然后在日志中记录ping的结果,用来监测网络连通情况. 代码: [python]from time import *from subprocess import *w ...
- IIS下众多网站,如何快速定位某站点日志在哪个文件夹?
windows2008,iis 多站点, 日志.应用程序池都是默认设置, 没有分开………… Logs目录里面有W3SVC43,W3SVC44,W3SVC45,W3SVC46.....等等日志文件夹. ...
- .net 文件接口的封装,写日志,创建文件log
public class FileSupport { public static FileSupport Instance = new FileSupport(); public static str ...
- 写日志(log)
已下为我自己写的一个写日志的类,比较简洁. <?php class Log { /** * @Purpose : 写日志 * @Method Name : writeLog() * @param ...
- logback将日志写入不同文件夹里
转载:logback不同业务的日志打印到不同文件 一.logback.xml文件配置如下: <?xml version="1.0" encoding="UTF-8& ...
- cocos2d-js 写日志log 查看日志log Android调试查看log
1 输出日志的方式,当然是cc.log了 2 如何查看日志? a)如果小程序可以先在浏览器上跑,例如用chrome,在控制台就可以看到输出的log: b)如果在真机上调试, ...
- log4net 配置允许同时写日志到同一个文件
RollingFileAppender appender = new RollingFileAppender();... appender.LockingModel = new FileAppende ...
- MySQL更改了my.ini的#Path to the database root后,数据还写到原来的文件夹
重新启动数据库 http://www.cnblogs.com/argenbarbie/p/4090494.html
- 在服务器上log4net没写日志
登录到服务器上,发现log4net没写日志 在相应文件夹加上User用户的写权限后恢复正常了.
随机推荐
- java布局学习 (二)
前文中介绍了FlowLayout和BorderLayout 本文我们将会继续介绍java中的布局方式 (3)GridLayout 网格布局 这种布局会将整个容器划分成M行*N列的网格. 如下图: ...
- 移动端 iframe的使用
对于iframe的设定有几个css属性常用 overflow:hidden;width:100%;当这样使用inframe内部中使用overflow,iframe会被撑开,导致width与overfl ...
- java context 讲解
在 java 中, 常见的 Context 有很多, 像: ServletContext, ActionContext, ServletActionContext, ApplicationContex ...
- Custom work flow
http://runjs.cn/detail/99epj1t2 http://www.cqroad.cn/ https://jsplumbtoolkit.com/demo/flowchart/dom. ...
- 常用快捷键(WebStorm, Eclipse, Sublime)
WebStorm 常用快捷键 Ctrl + / 单行注释// Ctrl + Shift + / 块注释/*…*/ Ctrl + D 复制行 Ctrl + Y 删除行 Ctrl + X 剪切(删除)行, ...
- LR中线程和进程的区别
LoadRunner中的进程与线程 1.进程与线程的区别: 进程和线程的区别是什么?进程和线程都是由操作系统所体会的程序运行的基本单元,系统利用该基本单元实现系统对应用的并发性.进程和线程的区别 ...
- django关系对象映射(Object Relational Mapping,简称ORM)
Model 创建数据库,设计表结构和字段 django中遵循 Code Frist 的原则,即:根据代码中定义的类来自动生成数据库表 from django.db import models clas ...
- 设置button键隐藏文字text
新手的第一天,从最简单的view开始做起.首先先来做个最简单的button携带不可见文本,想要的时候,get它就行了. 编程的都知道,get .set方法,就不多介绍了. 创建一个类,MyButto ...
- ASP.net如何保证EF操作类线程内唯一
说到线程内唯一,肯定会想到单例模式,但是如果多用户访问网站就会出现问题.ASP.net中有两种方法可以保证EF操作类线程内唯一(目前只会这两种,以后有好的方法再添加): 1.httpcontext(实 ...
- android xml中的xliff属性
<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xliff=" ...