写日志 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用户的写权限后恢复正常了.
随机推荐
- CentOS手动编译安装gcc
最近尝试了fedora.ubuntu.mint.debian.opensuse等多种linux发行版,与CentOS比较之后还是感觉之前用的CentOS比较熟悉,比较习惯.现在CentOS的最新版本为 ...
- Repeater的Item项绑定DropDownList
前台页面: <asp:Repeater ID="rptJgtList" runat="server" OnItemDataBound="rptJ ...
- AngularJs的UI组件ui-Bootstrap
http://www.cnblogs.com/pilixiami/p/5597634.html
- Web 2D/3d
首选应该是H5,通过现成的js库来实现,兼容性应该不错 其次可以考虑使用Unity3d,开发起来应该比较快 搜集点资料先放起来~ Unity3d: http://unity3d.com/cn/get- ...
- logstash实战
官网上的文档没有更新,估计快商业化了,elasticsearch和kibana 都内嵌了不用再下载,可以参看1.3.3的,除了打个包外没啥区别 http://logstash.net/docs/1.3 ...
- js中的this,call及apply
在前端网看了这么一篇文章,觉得讲得还不错,不深入但易懂,所以我这里把这个经典的问题也记下来. 1:声明式函数与定义函数表达式 console.log(f1);//f1() console.log(f2 ...
- FlasActionScript3随学随机
1.跳转页面代码.下载代码(new URLRequest(下载地址)): var request1:URLRequest=new URLRequest("http://www.baidu.c ...
- Linux-4.4-x86_64 内核配置选项简介【转】
转自:http://fx114.net/qa-188-150553.aspx 本篇文章主要介绍了"Linux-4.4-x86_64 内核配置选项简介",主要涉及到Linux-4.4 ...
- CSS3 笔记二(Gradients)
CSS3 Gradients Two types of gradients: Linear Gradients (goes down/up/left/right/diagonally) Radial ...
- Dynamics AX 2012 R2 通过数据源保存记录时触发的方法
我们都知道,在窗体上保存记录时,会像在表上保存时一样,触发很多方法.这里Reinhard找到了一个流程图,看看都触发了哪些方法,并且这些方法是以怎样的顺序被触发的. 窗体上数据源的Validate() ...