how to read text file from bottom going up (reverse)..
the start of every log is the time stamp enclosed in "[" and "]"
i wanted to read the last log based on the sample below where it should be:
[1/26/12 1:06:11:621 CST] 0000003b ExceptionUtil E CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "getObjects" on bean "BeanId
this is the sample code i use to read the log file:
TextReader tr = new StreamReader("c:\log.txt");
if i use: string endText = tr.ReadToEnd(), this will give me the last line which is:
how can i get to read the start of this last log from bottom up?
thanks in advance.
[1/25/12 1:06:11:652 CST] 0000003b LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[1/25/12 1:06:33:027 CST] 00000037 WSRdbManagedC W DSRA9510W: Custom property preTestSQLString should not be empty if the pre-test connection option is selected.
[1/25/12 1:14:41:159 CST] 00000025 LdapRegistryI A SECJ0419I: The user registry is currently connected to the LDAP server ldap://SANETDCPRD01:389.
[1/26/12 1:06:11:621 CST] 0000003b LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[1/26/12 1:06:11:621 CST] 0000003b ExceptionUtil E CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "getObjects" on bean "BeanId(FileNetEngine#Engine-ejb-ws.jar#Engine, null)". Exception data: com.filenet.api.exception.EngineRuntimeException: SECURITY_LDAP_PROVIDER_FAILED: LDAP Provider Access failed for principal 'P8PEAdmin_DEV'. Root cause: SANETDCPRD01:3268; socket closed
Re: how to read text file from bottom going up (reverse)..
If the file was one with fixed length records then it would be simple as you would know the byte postion of each record based on recordlength and record number. You would know the number of records based on record length and size of file but in the case of variable length records there is no way to tell without having a header that would tell you where each record starts.
You could read the entire file into memory then split() the file into an array and then read the array down from the highest index to 0.
Last edited by DataMiser; February 13th, 2012 at 12:40 PM.