Previous Next

Thread: LogParser through Windows Service

Last post 04-15-2008 8:39 PM by Ya Ya. 4 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (5 items)

Sort Posts:

  • 04-07-2008, 12:38 AM

    • Ya Ya
    • Not Ranked
    • Joined on 06-01-2006, 9:15 PM
    • Posts 3

    LogParser through Windows Service

    Hi all, I am working on small project using C# (2005) to use LogParser to query a particular server to grab it's log and transfer the log to SQL2005.

    I am able to do so if I access the LogParser through IE (through interface like letting the user select the server, date/time to parse etc). But when I transfer the entire script into Windows Service, I cannot get anything at all.

    Below is part of the codes that I have. For the Windows Service part, if I were to comment off the line LogRecordSet oRecordSet = oLogQuery.Execute( query, oEVTInputFormat ); it works (as in if I were to .write the query string out, I am able to) but when I put that line in, nothing happens although the service is started. Hope some experts here can help me! Thanks in advance!

    LogQuery oLogQuery = new LogQuery();
    EventLogInputFormat oEVTInputFormat = new EventLogInputFormat();
    oEVTInputFormat.direction = "BW";
    string query = @"SELECT * FROM ";
    if ( _ip != null )
    {
    if ( _ip != "local" )
    {
    query = query + "\\\\" + _ip + "\\SYSTEM";
    }
    }
    query = query + " WHERE (1 = 1)";
    if ( _lastmessageon != null )
    {
    query = query + " AND (TO_DATE(TimeGenerated) > TO_DATE(TIMESTAMP( '" + Common.MyFunctions.FormatDateTime( _lastmessageon, "yyyy-MM-dd hh:mm:ss" ) + "', 'yyyy-MM-dd hh:mm:ss')))";
    }
    LogRecordSet oRecordSet = oLogQuery.Execute( query, oEVTInputFormat );

    .... (codes to insert into SQL2005)


    oRecordSet.close();

     

  • 04-08-2008, 3:26 PM In reply to

    Re: LogParser through Windows Service

    You need to configure your service to run as an account that has access to the remote server. This can be an AD account or if you create an account with the same name and password on all of the servers then that will work too.

  • 04-08-2008, 8:23 PM In reply to

    • Ya Ya
    • Not Ranked
    • Joined on 06-01-2006, 9:15 PM
    • Posts 3

    Re: LogParser through Windows Service

    My system does has access to the remote server. As mentioned, when I tested the exact same code as an application, it works, but when I transferred it to windows service, it stops at the execute line without throwing any errors.

  • 04-11-2008, 6:00 AM In reply to

    Re: LogParser through Windows Service

    Hi Ya Ya,

    Although your system has access to the remote server, it doesn't mean windows service has sufficient permission to the remote server. By default, windows service is running with minimal user rights. Grant an account with the user rights that your code may require. You can find some description here:

    http://support.microsoft.com/kb/821794

     

    Zhao Ji Ma
    Sincerely,
    Microsoft Online Community Support

    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • 04-15-2008, 8:39 PM In reply to

    • Ya Ya
    • Not Ranked
    • Joined on 06-01-2006, 9:15 PM
    • Posts 3

    Re: LogParser through Windows Service

    oh.... ok.... thanks but how do i go about doing it?

    Does that mean that I have to create a specific account in every server which my service need to LP?

Page 1 of 1 (5 items)
Page view counter