public static void WriteLog(string msg)
        {
            string appPath = AppDomain.CurrentDomain.BaseDirectory;
            string ServerPath = appPath + @"\Log" + DateTime.Now.ToString("yyyyMMdd") + ".txt";

StreamWriter srWriter = new StreamWriter(ServerPath, true);
            string WriteStr = "************************************************************************************************\r\n";
            WriteStr += "Date:" + DateTime.Now.ToString() + "  \r\n" + msg;
            srWriter.WriteLine(WriteStr);
            srWriter.Close();
        }

另附上js的提示的换行写法:

alert("您确定提交整个问卷吗?\n\n提交后将不能再填写各个工种的用工需求,整个问卷将就此结束!")

confirm("您确定提交整个问卷吗?\n\n提交后将不能再填写各个工种的用工需求,整个问卷将就此结束!")

//事物处理,catch部分是写日志的方法
        public static bool TransactionAction(string SQL, string TransactionName)
        {
            SqlConnection myConnection = new SqlConnection(SQLServer.SQLConnectionString);
            myConnection.Open();
            SqlCommand myCommand = myConnection.CreateCommand();
            SqlTransaction myTrans;
            myTrans = myConnection.BeginTransaction(IsolationLevel.ReadCommitted, TransactionName);
            myCommand.Connection = myConnection;
            myCommand.Transaction = myTrans;
            try
            {
                myCommand.CommandText = SQL;
                myCommand.ExecuteNonQuery();

myTrans.Commit();
                return true;
            }
            catch (Exception ee)
            {
                string path = @"D:\webroot\ErrorLog";
                DirectoryInfo di = Directory.CreateDirectory(path); //在path下创建文件夹
                string strPath = path + "file://vipspace_error/_" + System.DateTime.Now.ToString("yyyyMMdd") + ".txt";
                StreamWriter srWriter = new StreamWriter(new FileStream(strPath, FileMode.OpenOrCreate), Encoding.GetEncoding("Unicode"));
                string WriteStr = "Date:" + DateTime.Now.ToString() + "  Error:" + ee.Message.ToString() + " SQL:" + SQL;
                srWriter.WriteLine(WriteStr);
                srWriter.Flush();
                srWriter.Close();

myTrans.Rollback(TransactionName);
                return false;
            }
            finally
            {
                myConnection.Close();
            }
        }

判断文件是否存在,如存在并将其删除

public static bool IsExistsFile(string FilePath)
{
if (File.Exists(FilePath) == true)

//****删除文件
File.Delete(FilePath);
return true;
}
return false;

C#中简单的写日志的方法的更多相关文章

  1. php 简单通用的日志记录方法

    使用file_put_contents 方法来实现简单便捷的日志记录功能 方法1: // use \r\n for new line on windows, just \n on linux func ...

  2. SSM-MyBatis-03:Mybatis中简单的整合日志

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------简单的整合日志,首先提供俩种方式,log4j和logback简单的说一下logback,他由log4j的原作者编 ...

  3. 怎么在.NetCore3.0 中使用Log4net 写日志 及读取配置文件的信息

    1:安装Log4Net的 NuGet 包: 我们通常之需要安装这一个包即可,其他的主包会自动被添加进来: insatll-package  Microsoft.Extensions.Logging.L ...

  4. php项目中常用的log日志记录方法

    function log_result($str) { if (LOG_WRITEOUT == 1) { $fp = fopen ( "log.txt", "a+&quo ...

  5. VC++ 中简单操作MP3音乐的方法,小结

    #include <windows.h> #include <stdio.h> #include <mmsystem.h> #include <shellap ...

  6. C# 简单粗暴写日志

    public static void WriteLog(string text) { string path = AppDomain.CurrentDomain.BaseDirectory; path ...

  7. C# 写日志的方法

    public void WriteLog(string msg)        {            string filePath = AppDomain.CurrentDomain.BaseD ...

  8. C# 简单的往txt中写日志,调试时很有用

    原文 http://blog.csdn.net/hejialin666/article/details/6106648 有些程序在调试时很难抓住断点(如服务程序),有些程序需要循环无数次,要看每一次或 ...

  9. kettle作业中的js如何写日志文件

    在kettle作业中JavaScript脚本有时候也扮演非常重要的角色,此时我们希望有一些日志记录.下面是job中JavaScript记录日志的方式. job的js写日志的方法. 得到日志输出实例 o ...

随机推荐

  1. 单链表的实现---SingleLinkedList

    单链表的实现,定义为SingleLinkedList class Node<AnyType>{ //结点Node类 public AnyType data; public Node< ...

  2. 解决Nginx的connect() to 127.0.0.1:8080 failed (13: Permission denied) while connect

    在进行Nginx+Tomcat 负载均衡的时候遇到了这个权限问题,在error.log日志中.我们能够看到例如以下: connect() to 127.0.0.1:8080 failed (13: P ...

  3. C# - is

     Checks if an object is compatible with a given type. An is expression evaluates to true if the pr ...

  4. UVA 439 Knight Moves(BFS)

    Knight Moves option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=3 ...

  5. ubuntu突然卡住

    ctrl+alt+f1.进username和password.然后进入: killall gnome-sesseion sudo pkill X 版权声明:本文博主原创文章,博客,未经同意不得转载.

  6. 2014.06.14 GlusterFS技术交流视频

    6月14线下GlusterFS视频交流.高清视频是非常好的,我初听言论方面,谈到迅速,似乎不是很清楚,讲座结束后速度需要改进.谢谢能力的天空AbleSky高大内设,谢谢学生参加. 在线公开课:http ...

  7. ASP.NET 异步编程

    ASP.NET 异步编程 相关博文: 异步编程 In .NET(回味无穷!!!) ASP.NET sync over async(异步中同步,什么鬼?) 本来这篇博文想探讨下异步中的异常操作,但自己在 ...

  8. 但从谈论性能点SQL Server选择聚集索引键

    简单介绍 在SQL Server中,数据是按页进行存放的.而为表加上聚集索引后,SQL Server对于数据的查找就是依照聚集索引的列作为keyword进行了. 因此对于聚集索引的选择对性能的影响就变 ...

  9. MEF初体验之四:Imports声明

    组合部件使用[System.ComponentModel.Composition.ImportAttribute]特性声明导入.与导出类似,也有几种成员支持,即为字段.属性和构造器参数.同样,我们也来 ...

  10. error while loading shared libraries: libpthread.so.0: cannot open shared object file: No such file

    安装rac10g,出现例如以下错误: [root@rac2 oracle]# /u01/product/crs/root.sh WARNING: directory '/u01/product' is ...