TraceLog.cs 累积 C#
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- using System.Diagnostics;
- namespace UtilityClass
- {
- public class TraceLog : TraceListener
- {
- // 初始化时给定一个日志文件位置
- private string filePath;
- public TraceLog()
- : this("")
- { }
- public TraceLog(string filepath)
- {
- if (filepath.IndexOfAny(Path.GetInvalidFileNameChars()) > -)
- {
- ShowMsg.ShowErr(null, "指定路径无效!\r\n\r\n请重新设置日志文件路径!");
- Trace.Listeners.Clear();
- return;
- }
- filePath = ConvertX.IsNullOrEmpty(filepath) ? AppDomain.CurrentDomain.BaseDirectory + "\\Error.Log" : Path.GetFullPath(filepath);
- }
- /// <summary>
- /// 保存 错误信息 到指定日志
- /// 此方法已重写 实际效果同 WriteLine
- /// </summary>
- public override void Write(string message)
- {
- File.AppendAllText(filePath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Environment.NewLine + message + Environment.NewLine);
- }
- /// <summary>
- /// 保存 错误信息 到指定日志
- /// </summary>
- public override void WriteLine(string message)
- {
- File.AppendAllText(filePath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Environment.NewLine + message + Environment.NewLine);
- }
- /// <summary>
- /// 输入一个 Exception 对象
- /// 它将在日志文件中保存 错误信息 和 堆栈信息
- /// </summary>
- public override void WriteLine(object o)
- {
- string msg = "";
- Exception ex = o as Exception;
- if (ex != null)
- {
- msg = ex.Message + Environment.NewLine;
- msg += ex.StackTrace;
- }
- else if (o != null)
- {
- msg = o.ToString();
- }
- WriteLine(msg);
- }
- /// <summary>
- /// 输入一个 错误信息 和一个 分类名称
- /// 它将在日志文件中保存 错误信息
- /// </summary>
- public override void WriteLine(string message, string category)
- {
- string msg = "";
- if (!ConvertX.IsNullOrEmpty(category))
- {
- msg = category + ":";
- }
- msg += message;
- WriteLine(msg);
- }
- /// <summary>
- /// 输入一个 Exception 对象和一个 分类名称
- /// 它将在日志文件中保存 错误信息 和 堆栈信息
- /// </summary>
- public override void WriteLine(object o, string category)
- {
- string msg = "";
- if (!ConvertX.IsNullOrEmpty(category))
- {
- msg = category + ":";
- }
- if (o is Exception)
- {
- var ex = (Exception)o;
- msg += ex.Message + Environment.NewLine;
- msg += ex.StackTrace;
- }
- else if (o != null)
- {
- msg = o.ToString();
- }
- WriteLine(msg);
- }
- }
- }
TraceLog.cs 累积 C#的更多相关文章
- Program.cs 累积_C#
using System; using System.Diagnostics; using System.Threading; using System.Windows.Forms; using Ut ...
- Enterprise Library 6.0 参考源码索引
http://www.projky.com/entlib/6.0/Diagnostics/Tracing/DiaLib.cs.htmlhttp://www.projky.com/entlib/6.0/ ...
- 修改AssemblyInfo.cs自动生成版本号
一. 版本号自动生成方法 1.把 AssemblyInfo.cs文件中的[assembly:AssemblyVersion("1.0.0.0")]改成[assembly:Assem ...
- [C#] 剖析 AssemblyInfo.cs - 了解常用的特性 Attribute
剖析 AssemblyInfo.cs - 了解常用的特性 Attribute [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5944391.html 序 ...
- Atitit 软件架构方法的进化与演进cs bs soa roa msa attilax总结
Atitit 软件架构方法的进化与演进cs bs soa roa msa attilax总结 1.1. 软件体系架构是沿着单机到 CS 架构,再到 BS 的三层架构甚至多层架构逐步发展过来的,关于 ...
- 从java文件和CS文件里查询方法使用次数工具
前几天,领导让我找一下老系统(Java)里getRemoteUser方法都哪个文件用了,package是什么,方法被调用了多少次,当时因为着急,所以,直接人工找的,但是以后要是再出现,人工找就太讨厌了 ...
- 关于 WP 开发中.xaml 与.xaml.cs 的关系
今天我们先来看一下在WP8.1开发中最长见到的几个文件之间的关系.比较论证,在看这个问题之前我们简单看看.NET平台其他两个不同的框架: Windows Forms 先看看Window Forms中的 ...
- .net 用户控件ascx.cs注册js脚本代码无效果
在.net web项目中碰到一个比较奇怪的问题,网上没找到解决方案,先自己mark一下 问题描述: 添加一个用户控件ascx,在后端.cs添加js注册脚本,执行后没有弹出框 注册脚本为: this.P ...
- DateHelper.cs日期时间操作辅助类C#
//==================================================================== //** Copyright © classbao.com ...
随机推荐
- 超级好用的C++万能头文件
#include<bits/stdc++.h>包含了目前c++所包含的所有头文件 对比: #include <iostream> #include <cstdio> ...
- Windows XP系统服役13年今正式退休
清明已过,服役13年的微软Windows XP系统也于今日正式“退休”.尽管这之后XP系统仍可以继续使用,但微软不再提供官方服务支持.对于中国数以亿计的XP用户来说,一方面是对已经使用了13年的操作系 ...
- JSP--TOMCAT-MYSQL web页面查询
queryStudent.jsp代码如下 <%@ page language="java" contentType="text/html; charset=gb23 ...
- K - Strange Country II 暴力dfs判断有向图是否连通//lxm
You want to visit a strange country. There are n cities in the country. Cities are numbered from 1 t ...
- 如何查看linux命令行操作的历史记录-linux
前言 由于刚开始学习linux,对命令行不熟悉,可以查看使用过的命令行历史记录,熟悉命令行并熟练操作,对命令行进行深入地理解. 系统环境 OS:ubuntu16.04. 操作过程 在主文件夹目录即ho ...
- Finally什么时候会被执行
PS:有return意味着程序结束,他一定会在程序结束前执行: PS: return返回前 会把数据存储到指定的位置,基本类型是不会改变的.引用类型是会影响修改的值的
- 当php版本为5.6时的提示信息解决方法
ecshop修饰符preg_replace/e不安全的几处改动 Strict standards: Only variables should be passed by reference in D: ...
- DOS批处理 - 函数教程
DOS Batch - Function Tutorial What it is, why it`s important and how to write your own. Description: ...
- 解决 php提交表单到当前页面,刷新会重复提交 的问题
http://blog.csdn.net/u012466451/article/details/68952280
- Oracle 表空间与数据文件
-============================== --Oracle 表空间与数据文件 --============================== /* 一.概念 表空间:是一个或多 ...