Maqsood, now i can get the Message for EventLog, but failed write the Message
string to a MDB, Would you please check my code, as below:
//-----------------------------------------------------------------------
//Wrote by Michael April 30 2005
//-----------------------------------------------------------------------
using System.Text;
using System.Diagnostics;
using System.Threading;
using System;
using System.Text.RegularExpressions;
using System.Data.OleDb;
public class LogInfo4
{
public static void Main(String[] args)
{
string log="System";
string machine="MyDC001";
EventLog aLog = new EventLog();
aLog.Log = log;
aLog.MachineName = machine;
Console.WriteLine("There are {0} entr[y|ies] in the log:",
aLog.Entries.Count);
//get string for print Message
foreach (EventLogEntry entry in aLog.Entries)
{
string strText = entry.Message;
string PrintDocNum,
PrintDocName,PrintUser,PrintServerName,PrintByte,PrintIp,PrintPages;
string strMatch = @"^Document (\d+), *(.+) owned by (.+) was printed on
(.*) via port IP_(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\. Size in bytes:
(\d+); pages printed: (\d+)";
Regex re = new Regex(strMatch);
Match m = re.Match(strText);
if(m.Success)
{
PrintDocNum = m.Groups[1].ToString();
PrintDocName = m.Groups[2].ToString();
PrintUser = m.Groups[3].ToString();
PrintServerName = m.Groups[4].ToString();
PrintIp = m.Groups[5].ToString();
PrintByte = m.Groups[6].ToString();
PrintPages = m.Groups[7].ToString();
OleDbConnection conn = new OleDbConnection();
// TODO: Modify the connection string and include any
// additional required properties for database.
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data source= E:\April30\Db\TestDb.mdb" ;
conn.Open();
string sqlInsert=@"insert into
TestTable(DocNum,DocName,User,ServerName,Byte,Ip,Pages) values
(@PrintDocNum,@PrintDocName,@PrintUser,@PrintServerName,@PrintByte,@PrintIp,@PrintPages)";
OleDbCommand cmd1=new OleDbCommand(sqlInsert,conn);
cmd1.Parameters.Add("@PrintDocNum",System.Data.OleDb.OleDbType.VarChar,50,PrintDocNum);
cmd1.Parameters.Add("@PrintDocName",System.Data.OleDb.OleDbType.VarChar,50,PrintDocName);
cmd1.Parameters.Add("@PrintUser",System.Data.OleDb.OleDbType.VarChar,50,PrintUser);
cmd1.Parameters.Add("@PrintServerName",System.Data.OleDb.OleDbType.VarChar,50,PrintServerName);
cmd1.Parameters.Add("@PrintByte",System.Data.OleDb.OleDbType.VarChar,50,PrintByte);
cmd1.Parameters.Add("@PrintIp",System.Data.OleDb.OleDbType.VarChar,50,PrintIp);
cmd1.Parameters.Add("@PrintPages",System.Data.OleDb.OleDbType.VarChar,50,PrintPages);
//Console.WriteLine("Command Created");
cmd1.ExecuteNonQuery();//insert string
//Console.WriteLine("insert end");
conn.Close();
}
}
}
}
Maqsood Ahmed said:
Hello,
I didn't experience any problem with Event Logs from remote system.
Can you paste the code you were trying for getting logs from remote
system?
Bye
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net