« Previous Next »

Answered Thread: not able to read .CSV file using LogParser

Last post 07-17-2009 3:37 PM by maximusdm. 3 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (4 items)

Sort Posts:

  • 07-16-2009, 2:05 PM

    not able to read .CSV file using LogParser

    Hi all,

    I managed to create a .CSV file using the COMIISW3CInputContextClassClass to read an IIS log, however I have a CSV file which I am trying to read and is giving me the error below:

    {"Error parsing query: SELECT clause: Syntax Error: unknown field 'date1' [Record field does not exist.]"}

    Sample code:
    --------------------
    query="select date1, date2 INTO C:\\A.csv FROM c:\\B.log"

    public static void GetResultsFromBatch_CSV(string query)
    {
     LogQueryClassClass LogParser = new LogQueryClassClass();
     COMCSVInputContextClassClass  pObjInput  = new COMCSVInputContextClassClass();
     COMCSVOutputContextClassClass pObjOutput = new COMCSVOutputContextClassClass();

     try
     {
      LogParser.ExecuteBatch(query, pObjInput, pObjOutput);
     }
     catch (Exception e)
     {
     }
    }


    Sample source CSV file:
    ------------------------
    #2009:07:15 11:00:26:23 - 2009:07:15 12:00:00:00
    date1,date2,id1,status1,sink1,sink2,sink3,id2,id3,status2
    2009:07:15 16:00:26:23,2009:07:15 11:00:26:23T-5,65535,Debug,LoggingTrace,AgentService.exe,,5564,4,[Debug] Init agent.^

    Any ideas? Thank you!

    MDM
  • 07-16-2009, 2:32 PM In reply to

    Answered Re: not able to read .CSV file using LogParser

    I see two problems, Please pick up which is apropriate for you (I guess both :) )

    First: If you are using same csv file as posted above then you have to either remove forst line(starting with '#' ) or 'nSkipLineyou have to use parameter s' to set no of liner to skip

    Second: You have to use a 'iTsFormat' (input timestamp format) parameter if you want date1 field as date, then you have to set 'iTsFormat'  something like yyyy:MM:dd hh:mm:ss:ll (I have not tested it please check it again). If you want same timestamp format for output then use same value for 'oTsFormat' parameter.

    Anwarhusen
    Please refer Log Parser help for further reference
  • 07-16-2009, 4:14 PM In reply to

    Re: not able to read .CSV file using LogParser

    Anwarhusen,

    Thank you so much. You pointed me to the right direction! I ended up using the following:

    logparser "select date1,id1 INTO C:\temp\a.csv FROM C:\temp\b.log" -i:CSV -iHeaderFile:"c:\Header.csv" -nSkipLines:2 -iTsFormat:"yyyy-MM-dd?hh:mm:ss"

    That works perfectly for my .CSV file. One other thing I was trying to find out was that if it's possible to read the same .CSV containing the delimiter "|" instead of a comma ",". Here is the format of the file:

    #SERVER001
    #2009:07:15 11:00:26:23 - 2009:07:15 12:00:00:00
    2009:07:15 16:00:26:23|2009:07:15 11:00:26:23T-5|65535|Debug|TraceFacade|Service.exe||5564|4|[Debug] Init delivery agent.^

    Is is possible? I could not find anything on the Logparser help other than TEXTWORD format.

    Thank you!

    MDM
  • 07-17-2009, 3:37 PM In reply to

    Re: not able to read .CSV file using LogParser

    ok I found the answer on: http://forums.iis.net/t/1145337.aspx

    :)

    MDM
Page 1 of 1 (4 items)
Microsoft Communities