Feng's profileLudwig的骇客帝国BlogLists Tools Help

Blog


    March 20

    EventLog

    EventLog.CreateEventSource(source, logName);
    LogName, 日志的名称。这可以是 Application、System 和 Security,或一个自定义的日志名称。默认值为空字符串 ("")。

    默认情况下,服务器上存在三个日志文件: Application、System 和 Security。应用程序和服务使用 Application 日志文件。设备驱动程序使用 System 日志文件。打开审核时,系统在 Security 日志中生成成功审核事件和失败审核事件。如果安装了其他应用程序(如 Windows Server 上的 Active Directory),则可能会有其他默认日志文件。另外,还可以在本地计算机或远程计算机上创建自定义日志文件。与组件向默认的 Application 日志写入事件相比,自定义日志可以更详细地组织日志项。

    如果写入事件日志,则仅指定 Log (即LogName)属性是不够的。必须将 Source 属性与事件日志资源关联,才能将其连接到特定的日志。若仅从日志中读取,则不需要指定 Source,但必须使某个事件源与服务器注册表中的事件日志资源关联。只能指定 Log 名称和从中读取的 MachineName(服务器计算机名称)。

    EventLog

    Code:
    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")){
                EventLog.CreateEventSource("MySource", "Application");  //日志写入"应用程序"分类下
            }
            // 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.");
        }
    }

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://ludwigxu.spaces.live.com/blog/cns!1B1DC2CBB79F56F9!231.trak
    Weblogs that reference this entry
    • None