写log日志,如何记录是哪个类或者那个方法调用的啊 System.Diagnostics.EventLog log = new System.Diagnostics.EventLog("TestApp");log.WriteEntry("This is a log string."); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在调用方法或事件时,写人log即可 to:ET2004(ET2004) 我是在.net compact framework下做的,好像不支持Evengtlog 的 还有没有什么别的方法 啊to:yanyzty(歪打正着) 我是想能够自动的写入啊,而不需要程序员每次都要将那些信息写入谢谢各位指点了啊:) .NET Compact Framework? 你的开发平台是 Windows CE 吧?是不是 Windows CE 本身没有事件日志?如果是这样的话,就只能写入文件日志了。下面的代码是基于 .NET Framework 1.1 的,不知道 .NET Compact Framework 是否支持。using( StreamWriter writer = new StreamWriter(logFilename, true, System.Text.Encoding.Unicode) ){ string logTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss\t", CultureInfo.InvariantCulture); string logType = String.Format(CultureInfo.InvariantCulture, "[{0}]\t", type); string message = String.Format(CultureInfo.InvariantCulture, logString, args); writer.Write(logTime); writer.Write(logType); writer.WriteLine(message); writer.Close();} 忘记加上方法原型了:(EventLogEntryType 可以用 object 替换)public static void WriteFileLog(EventLogEntryType type, string logFilename, string logString, params object[] args) 在我是在.net compact framework下做的,好像不支持Evengtlog 的 还有没有什么别的方法 啊急 .NET Compact Framework也就是WinCE或者WinCE.NET中没有log,你就用XML自己定义一个log就可以了写log的Class如下using System;namespace Cnming.Classes.Base{ /// <summary> /// ClassEventLog 的摘要说明。 /// </summary> public class ClassEventLog { private System.Diagnostics.EventLog eventLogService; public ClassEventLog() { this.eventLogService = new System.Diagnostics.EventLog(); // // eventLogService // this.eventLogService.Log = "Application"; this.eventLogService.Source = "LogTest"; } #region 写日志 /// <summary> /// 写日志 /// </summary> public void Write_Event(string p_strSource, string p_strMessage, System.Diagnostics.EventLogEntryType p_EventType) { try { int m_intEventID = 10000; eventLogService.Source = p_strSource; eventLogService.WriteEntry(p_strMessage, p_EventType, m_intEventID); } catch { } } #endregion }} asp.net 我想做个打印 把Repeater里的所有数据都打印出来 但有分页 想点一下打印按钮就把第2 ,3页的也一起 正则表达式高手请帮忙!! WINFORM控件状态控制解决方案 tostring方法的参数 又卡壳了,给ComboBox.SelectedValue付值 C#远程连接SQL 2000 ASP.NET导出EXECL出现乱码,在线等! ####### 求一个检测路径是否合法的正则表达式 ############### C#使用DataSet转成XML的问题 怎样可以修改XML?? datagrid (winform) 改变单元格颜色方法调用问题 如何让页面延迟显示?
还有没有什么别的方法 啊
to:yanyzty(歪打正着) 我是想能够自动的写入啊,而不需要程序员每次都要将那些信息写入
谢谢各位指点了啊:)
如果是这样的话,就只能写入文件日志了。下面的代码是基于 .NET Framework 1.1 的,不知道 .NET Compact Framework 是否支持。using( StreamWriter writer = new StreamWriter(logFilename, true, System.Text.Encoding.Unicode) )
{
string logTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss\t", CultureInfo.InvariantCulture);
string logType = String.Format(CultureInfo.InvariantCulture, "[{0}]\t", type);
string message = String.Format(CultureInfo.InvariantCulture, logString, args);
writer.Write(logTime);
writer.Write(logType);
writer.WriteLine(message);
writer.Close();
}
还有没有什么别的方法 啊
急
{
/// <summary>
/// ClassEventLog 的摘要说明。
/// </summary>
public class ClassEventLog
{
private System.Diagnostics.EventLog eventLogService;
public ClassEventLog()
{
this.eventLogService = new System.Diagnostics.EventLog();
//
// eventLogService
//
this.eventLogService.Log = "Application";
this.eventLogService.Source = "LogTest";
}
#region 写日志
/// <summary>
/// 写日志
/// </summary>
public void Write_Event(string p_strSource, string p_strMessage, System.Diagnostics.EventLogEntryType p_EventType)
{
try
{
int m_intEventID = 10000;
eventLogService.Source = p_strSource;
eventLogService.WriteEntry(p_strMessage, p_EventType, m_intEventID);
}
catch
{
}
}
#endregion
}
}