Asked by:
Get the latest logs from the log file

Question
-
Hi Everyone,
I am trying to fetch last 60 mins logs from my log file using powershell. Below is the sample of my log file:
2018-08-15T19:46:24.900 p1-rtap-dp-1054646217-44gcz prta_app: ERROR http-nio2-8180-exec-55 o.g.a.r.e.ReturnHeaderException.<init> - Exception occurred due toYou are not allowed to access Return for selected return period
2018-08-15T19:46:24.901 p1-rtap-dp-1054646217-44gcz prta_app: ERROR http-nio2-8180-exec-55 o.g.a.r.r.r.ReturnsRestController.getGSTR1Summary - ReturnHeaderException
Please help as I am stuck at this. I need to pull last 60 mins logs from the log file.
Thanks in advance
Rahul Goyal
Wednesday, August 15, 2018 10:17 PM
All replies
-
Use this:
$line = '2018-08-15T19:46:24.900 p1-rtap-dp-1054646217-44gcz prta_app: ERROR http-nio2-8180-exec-55 o.g.a.r.e.ReturnHeaderException.<init> - Exception occurred due toYou are not allowed to access Return for selected return period' $timestamp = [datetime]$line.SubString(0,23)
\_(ツ)_/
Wednesday, August 15, 2018 10:39 PM -
can't use this..
I have to do for every line in the log file
I want to get the latest logs from the log file not the timestamp.
Rahul Goyal
Wednesday, August 15, 2018 11:07 PM -
You need to post your script. We will not write it for you. If you don't know how to write a script then use the links below to learn PowerSHell or to find a script in the Gallery.
There is a link for script requests:
Please carefully review the following links to set your expectation for posting in technical forums.
This Forum is for Scripting Questions Rather than script requests
- Script Gallery.
- Script Center
- Script requests
- Posting guidelines
- Handy tips for posting to this forum
- How to ask questions in a technical forum
- Rubber duck problem solving
- How to write a bad forum post
- Help Vampires: A Spotter's Guide
- This forum is for scripting questions rather than script requests
\_(ツ)_/
Wednesday, August 15, 2018 11:10 PM -
What about this?
[string]$string =@" 2018-08-15T19:46:24.900 p1-rtap-dp-1054646217-44gcz prta_app: ERROR http-nio2-8180-exec-55 o.g.a.r.e.ReturnHeaderException.<init> - Exception occurred due toYou are not allowed to access Return for selected return period 2018-08-15T19:46:24.901 p1-rtap-dp-1054646217-44gcz prta_app: ERROR http-nio2-8180-exec-55 o.g.a.r.r.r.ReturnsRestController.getGSTR1Summary - ReturnHeaderException "@ $array = $string.Split("`n") Write-Host $array[$array.Count -1]
Wednesday, August 15, 2018 11:16 PM