net日志的编写_第1页
net日志的编写_第2页
net日志的编写_第3页
net日志的编写_第4页
net日志的编写_第5页
免费预览已结束,剩余2页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

using System using System Configuration using System Data using log4net using log4net Config using log4net Appender using log4net Layout using log4net Util namespace BizTalk DAL Log 日志文件处理 public sealed class LogUtil region 变量 ConfigurationSettings AppSettings protected static readonly log4net ILog logger LogManager GetLogge r System Reflection MethodBase GetCurrentMethod DeclaringType private static string logFilePath string Empty 日志文件 错误文件 处理文件路径 private static string str configfile E Suzhou Project EDI 代码 BizTalkSolution suzhou BizTalk suzhou Config Config DB config 日志文件的读写也由 xml 文件读取 private static string logErrFilePath System Configuration Configur ationManager AppSettings ErrFilePath private static string logWarnFilePath string Empty 日志文件路径 private static string logInfoFilePath System Configuration Configu rationManager AppSettings logFilePath endregion Ctr public LogUtil region 获得参数设置 根据配置文件里面参数名称读参数 public static string Get Parameter string ParameterName DataSet ds config BizTalk DAL Data XmlObject GetXml str config file string str xml proc ds config Tables ParameterName Rows 0 value ToString return str xml proc endregion region 写日志文件 Method public static void WriteLog string msg string filePath logFilePath FileAppender fa GetFileAppender filePath log4net Config BasicConfigurator Configure fa 写入日志 logger Debug msg 日志文件写入 public static void WriteLogInfo string msg string filePath logInfoFilePath string filePath Get Parameter logFilePath Trim FileAppender fa GetFileAppender filePath log4net Config BasicConfigurator Configure fa logger Info msg public static void WriteLogWarn string msg string filePath logWarnFilePath FileAppender fa GetFileAppender filePath log4net Config BasicConfigurator Configure fa logger Warn msg 错误文件写入 public static void WriteLogErr string msg string filePath logErrFilePath string filePath Get Parameter ErrFilePath Trim FileAppender fa GetFileAppender filePath log4net Config BasicConfigurator Configure fa logger Error msg endregion 取得日志文件位置和样式 文件路径 private static FileAppender GetFileAppender string filePath 日志文件布局 PatternLayout sLayout new PatternLayout date thread 5l evel logger ndc message newline sLayout Header Header r n sLayout Footer Footer r n 日志文件路径 string fileName filePath System DateTime Now ToStrin g yyyy MM dd System DateTime Now ToString yyyy M M dd Log log FileAppender fa new FileAppender sLayout fileName return fa 复制代码 using System using System Collections Generic using System Text using System Diagnostics namespace BizTalk DAL Log public class LogBase private static void Write string msg string category string path string Format c 0 log category using System IO StreamWriter sw new System IO StreamWriter p ath true try string lin string Format 2 0 r n 1 categor y msg DateTime Now ToString yyyy MM dd HH mm ss sw WriteLine lin sw Close catch Exception e Console WriteLine e sw Close public static void TraceWrite string message string category try if category I TraceSwitch mySwitch new TraceSwitch BizImpTrace Biztalk trace message if mySwitch TraceError Write message BizImpException Trace Listeners 1 WriteLine message BizImpExce ption else if category E TraceSwitch mySwitch new TraceSwitch BizExTrace B iztalk trace message if mySwitch TraceError System Diagnostics DefaultTraceListener Trace L isteners 2 Write message BizExException Trace Listeners 2 WriteLine message BizImpExce ption else if category R TraceSwitch mySwitch new TraceSwitch BizRouterTrace Biztalk trace message if mySwitch TraceError System Diagnostics DefaultTraceListener Trace L isteners 2 Write message BizRouterException Trace Listeners 3 WriteLine message BizRouterE xception else if mySwitch T

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论