How to use serilog splunk in .net core - splunk

I trying serilog with splunk cloud. When I try to log I am getting Error
Exception while emitting periodic batch from Serilog.Sinks.Splunk.EventCollectorSink: System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Serilog.Sinks.Splunk.EventCollectorSink.EmitBatchAsync(IEnumerable`1 events)
at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.OnTick()
Log.Logger = new LoggerConfiguration().Enrich.FromLogContext()
.WriteTo.EventCollector("URL", "token", restrictedToMinimumLevel: LevelAlias.Minimum,batchSizeLimit:1000000000).CreateLogger();

Related

Mulesoft error message propagation through deployed application

General explanation of the problem:
how can i get/log inside an application B, the error/exception message produced by an application A (error description and code are generated with a OnErrorPropagate). Application A is a Process API and B is an Experience Api both deployed on cloudHub.
More Details:
i have a Process API App. and a Experience API APP. deployed on CloudHub that retrieve client data from a DB.
.../getClient?client_Id=xxx
When inside the request the client_id params is not provided the below error message (generated inside an OnErrorPropagate) is shown
"message" : "bad request"
When a client call the Exp.API APP /getClient without the parameter, the PROCESS API APP (invoked by a flow inside the Exp.API implementation) respond with the above error message.... how can i retrieve this message in my Experience API Application?
If i try lo log the payload response (that should contain the error message) from an Experience API APP log, i always get an empty message.
So, is possible to pass an error message generated inside an OnErrorPropagate from an application (PROCESS API APP) to another app (EXPERIENCE API APP)?
All these applications are on cloudhub. Mulesoft 4
You can capture the the error response payload from the process API which will be present in the error object and set it as response for your experience API using this DW expression
#[output application/json --- error.exception.errorMessage.typedValue]
You should capture the payload response in the Experience API when you make the HTTP request to the Process API.

ASP.NET Core trace logging on Azure with Application Insights

I have an ASP.NET Core web project deployed to Azure with Application Insights configured. Insights is receiving data fine for requests etc. but I am unable to get it to display my logs.
I am using the vanilla Microsoft.Extensions.Logging framework and have a test error being logged on a controller action as
logger.LogError("Test application insights message");
In my Startup.cs Configure method I have set
loggerFactory.AddAzureWebAppDiagnostics();
... and can successfully see the error message appear in Azure logs streaming:
2017-04-14 11:06:00.313 +00:00 [Error] Test application insights message
However, I also want this message to appear in Application Insights trace but it is nowhere to be found. I think I need to configure the ILoggerFactory but not sure how and can't find any docs on the subject.
Thanks in advance for your help
case anybody else trying to resolve this, I got the results I wanted with the following:
loggerFactory.AddApplicationInsights(app.ApplicationServices);
For me, It only worked when I specified the InstrumentationKey to services.AddLogging in my Startup.cs like this:
services.AddApplicationInsightsTelemetry();
services.AddLogging(builder =>
{
// Only Application Insights is registered as a logger provider, get the key from appSettings.json file and add application insight
var instrumentationKey = Configuration.GetValue<string>("ApplicationInsights:InstrumentationKey");
builder.AddApplicationInsights(instrumentationKey);
});

Windows 8 app development. An error occurred while receiving the HTTP response

Whats wrong with this:
1-MyServiceReference.ServiceClient client = new MyServiceReference.ServiceClient();
2-MyServiceReference.User temp = await client.VerifyUser(user_email.Text);
it gives me the following Exception at line 2:
"An error occurred while receiving the HTTP response to {Service Url}. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details".

How to get details exception from published Web Api

Is there any way to get detail exception & Stack trace from deployed Web Api?
Even if I deployed in Debug mode, do I get detail error traces?
I got bellow message from server API
"message": "Processing of the HTTP request resulted in an exception.
Please see the HTTP response returned by the 'Response' property of
this exception for details."
This happened only in server, same code running perfectly in local machine.
Did you check the content-type for the request that you are performing?
Sometimes this error comes because you don't specify this value, e.g. "application/json" in the headers of the request.
If your scenario is to have a central place to log any exceptions that happen when requests are being processed, then I would suggest to take a look at 5.1 version of Web API (released couple of days back), specifically the Global Error Handling feature.
http://www.asp.net/web-api/overview/releases/whats-new-in-aspnet-web-api-21#global-error
If you go to the above page,you should notice ExceptionLoggerContext which gives you details of the exception.
About Web API versions 5.0 and before:
In these versions there was no really a central place for catching exceptions. ExceptionFilterAttributes caught exceptions for only certain areas of Web API.

How do I call a WCF service from RestSharp

Can someone post some sample code to access a WCF service from RestSharp. I am trying to get data into a MonoDroid application and RestSharp seemed pretty simple. However I cannot seem to find any sample code which works. I have hosted the WCF service on my website under shared hosting. I have posted the RestSharp code I am using below but I am getting an error.Can someone tell me what I am doing wrong here
var client = new RestClient("http://mysamplesite.com/testService");
// client.Authenticator = new HttpBasicAuthenticator(username, password);
var request = new RestRequest("gettestdata", Method.GET);
request.AddParameter("key", "");
// execute the request
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string
if (!string.IsNullOrWhiteSpace(response.Content) && response.StatusCode == System.Net.HttpStatusCode.OK)
DeserialiseData(content);
Server Error in Application \"MYSAMPLESITE.COM/TESTSERVICE\"
Internet Information Services 7.5
Error Summary
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Detailed Error Information
IIS Web Core Error Code 0x80070002
Requested URL http://www.mysamplesite.com:80/TestService/GetTestData
Physical PathD:\rwq1 \n
Logon MethodAnonymous \n Logon UserAnonymous \n
Most likely causes: \n \t
The directory or file specified does not exist on the Web server.
The URL contains a typographical error