I am using C# application and logging through nlog. It is writing in file as well as sending the logs through tcp to logstash.
Actual log file is (which is written by nlog in file):
2018-04-18 10:26:51 | [38] | ERROR | BankerbayPL.UserControl.BBNewsfeedControl.getNewsFeed(BBNewsfeedControl.ascx.cs:259) | Exception When Fetching Newsfeed url: http://localhost:8080/WebServices/GetNewsFeed data passed: ?newsId=000000&max=2 Exception details : System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:8080
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at BankerbayBL.RestClient.MakeRequest(String parameters) in E:\.Net v4 Chinese\trunk\BankerbayBL\RestClient.cs:line 101 :
2018-04-18 10:26:53 | [31] | ERROR | BankerbayPL.Global.Application_Error(Global.asax.cs:2970) | Unhandled exception : System.Web.HttpException (0x80004005): File does not exist.
at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath)
at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
2018-04-18 10:26:53 | [31] | ERROR | BankerbayPL.Global.Application_Error(Global.asax.cs:2976) | Unhandled Exception on RequestURL:/images/userProfilePic/Thumb_15_3279_15_09_2017.png
2018-04-18 10:26:53 | [31] | ERROR | BankerbayPL.Global.Application_Error(Global.asax.cs:2978) | Exception on UrlReferrer:http://localhost:3442/dashboard/
2018-04-18 10:26:53 | [30] | ERROR | BankerbayPL.Global.Application_Error(Global.asax.cs:2976) | Unhandled Exception on RequestURL:/images/userProfilePic/Thumb_4_2735_10_04_2018.png
2018-04-18 10:26:53 | [30] | ERROR | BankerbayPL.Global.Application_Error(Global.asax.cs:2978) | Exception on UrlReferrer:http://localhost:3442/dashboard/
2018-04-18 10:26:54 | [32] | ERROR | BankerbayPL.Global.Application_Error(Global.asax.cs:2976) | Unhandled Exception on RequestURL:/images/userProfilePic/Thumb_15_3279_15_09_2017.png
My logstash config file is:
input {
tcp {
host => "127.0.0.1"
port => 3443
mode => "server"
codec => multiline {
pattern => "^%{TIMESTAMP_ISO8601}"
what => "previous"
negate => true
}
}
}
filter {
grok {
match => [ "message", "^%{TIMESTAMP_ISO8601:logtime}%{SPACE}\|%{SPACE}\[%{NUMBER:thread_id}\]%{SPACE}\|%{SPACE}%{LOGLEVEL:loglevel}%{SPACE}\|%{SPACE}%{GREEDYDATA:classname}%{SPACE}\|%{SPACE}%{GREEDYDATA:logmessage}"]
}
date {
match => ["logtime", "yyyy-MM-dd HH:mm:ss"]
timezone => "GMT"
}
}
output {
file {
path => "C:/ServiceLogs/stashed.log"
codec => line { format => "custom format: %{logtime} %{thread_id} %{loglevel} %{classname} %{logmessage}"}
}
}
My output in log file is:
custom format: 2018-04-18 10:26:51 38 ERROR BankerbayPL.UserControl.BBNewsfeedControl.getNewsFeed(BBNewsfeedControl.ascx.cs:259) Exception When Fetching Newsfeed url: http://localhost:8080/WebServices/GetNewsFeed data passed: ?newsId=000000&max=2 Exception details : System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:8080
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at BankerbayBL.RestClient.MakeRequest(String parameters) in E:\.Net v4 Chinese\trunk\BankerbayBL\RestClient.cs:line 101 :
custom format: 2018-04-18 10:26:53 31 ERROR BankerbayPL.Global.Application_Error(Global.asax.cs:2976) | Unhandled Exception on RequestURL:/images/userProfilePic/Thumb_15_3279_15_09_2017.png 2018-04-18 10:26:53 | [31] | ERROR | BankerbayPL.Global.Application_Error(Global.asax.cs:2978) | Exception on UrlReferrer:http://localhost:3442/dashboard/ 2018-04-18 10:26:53 | [30] | ERROR | BankerbayPL.Global.Application_Error(Global.asax.cs:2970) Unhandled exception : System.Web.HttpException (0x80004005): File does not exist.
at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath)
at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
custom format: 2018-04-18 10:26:53 31 ERROR BankerbayPL.Global.Application_Error(Global.asax.cs:2970) Unhandled exception : System.Web.HttpException (0x80004005): File does not exist.
at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath)
at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
custom format: 2018-04-18 10:26:53 30 ERROR BankerbayPL.Global.Application_Error(Global.asax.cs:2976) Unhandled Exception on RequestURL:/images/userProfilePic/Thumb_4_2735_10_04_2018.png
custom format: 2018-04-18 10:26:54 32 ERROR BankerbayPL.Global.Application_Error(Global.asax.cs:2976) Unhandled Exception on RequestURL:/images/userProfilePic/Thumb_15_3279_15_09_2017.png
I don't the logs to be combined. Every line should be a different entry. How can I do that?