PDA

View Full Version : سیستم رویداد نگاری



rezaee2
چهارشنبه 08 خرداد 1392, 04:37 صبح
سلام دوستان

من نیاز دارم که اتفاقهایی که میوفته از قبیل اینکه چه کاربری در چه زمانی لوگین کرد و یا اینکه چه اطلاعاتی رو تغییر داد رو ثبت کنم...

کسی میتونه توضیح بده که چطور باید ایجادش کنم..؟

مثلا آیا جدولی باید برای هر جدولم ایجاد بشه که رویدادها در اون ثبت بشه؟

Tiam121
چهارشنبه 08 خرداد 1392, 08:19 صبح
معمولا برای اینکار از دیتابیس استفاده نمیشه و رویدادها رو توی فایل دخیره میکنن

alexmcse
چهارشنبه 08 خرداد 1392, 18:20 عصر
همین طور که دوست عزیز tiam121 گفتند باید از فایل استفاده کنی و یکی از راههای آن استفاده از کنترل EventLog است که در تولبار خود ویژوال وجود دارد
نمونه کد
using System;
using System.Diagnostics;
using System.Threading;

class MySample{

public static void Main(){

// Create the source, if it does not already exist.
if(!EventLog.SourceExists("MySource"))
{
// An event log source should not be created and immediately used.
// There is a latency time to enable the source, it should be created
// prior to executing the application that uses the source.
// Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog");
Console.WriteLine("CreatingEventSource");
Console.WriteLine("Exiting, execute the application a second time to use the source.");
// The source is created. Exit the application to allow it to be registered.
return;
}

// Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "MySource";

// Write an informational entry to the event log.
myLog.WriteEntry("Writing to event log.");

Console.WriteLine("Message written to event log.");
}
}