Serilog Splunk is not logging messages - .net-core

I have a simple console app with the following code, to log into Splunk which is not working. I dont see any logs in the Splunk dashboard. I have masked the url and token.
var url = "https://http-inputs-*****.splunkcloud.com/services/collector";
var log = new LoggerConfiguration()
.WriteTo.EventCollector(url, "49A89C45-****-47D2-8A4C-EF89DA*****", index:"app_crius_services")
.CreateLogger();
log.Error(JsonConvert.SerializeObject(new ExceptionMessage
{Index = "app_crius_services", Event = new Event()}));
log.Debug(JsonConvert.SerializeObject(new ExceptionMessage
{Index = "app_crius_services", Event = new Event()}));
log.Information(JsonConvert.SerializeObject(new ExceptionMessage
{Index = "app_crius_services", Event = new Event()}));
I am using the same URL and token to post similar kinds of messages using Postman, and those arrive successfully (I can see them in my Splunk dashboard).
Is there anything that I am doing wrong, or is my logger configuration is incorrect?

So serilog actually batches the events and scans those batches in an interval to make an http post, the issue was the program being exited before the scan happened. The following link demonstrates how to force flush the sink.
https://github.com/serilog/serilog-sinks-splunk/issues/95

Related

Problem using http GET request in flutter

So I got a template of a Flutter app that retrieves all its data from a website using HTTP get requests.
I have the following method that gets the list of resturaunts:
Future<Stream<Restaurant>> getNearRestaurants(LocationData myLocation, LocationData areaLocation) async {
String _nearParams = '';
String _orderLimitParam = '';
if (myLocation != null && areaLocation != null) {
_orderLimitParam = 'orderBy=area&limit=5';
_nearParams = '&myLon=${myLocation.longitude}&myLat=${myLocation.latitude}&areaLon=${areaLocation.longitude}&areaLat=${areaLocation.latitude}';
}
final String url = '${GlobalConfiguration().getString('api_base_url')}restaurants?$_nearParams&$_orderLimitParam';
final client = new http.Client();
final streamedRest = await client.send(http.Request('get', Uri.parse(url)));
return streamedRest.stream.transform(utf8.decoder).transform(json.decoder).map((data) => Helper.getData(data)).expand((data) => (data as List)).map((data) {
return Restaurant.fromJSON(data);
});
}
However when I swap the template's url variable for my own website, the app gets stuck since it cannot retrieve the same information from my website.
What could I be missing? Is the problem in the flutter code or the website?
Update 1:
I surrounded it with a try/catch block and it gave me a "bad certificate exception.". This might be because my website does not have a SSL certificate, so I added an exception to the HttpClient for my self-certified website:
bool _certificateCheck(X509Certificate cert, String host, int port) =>
host == '<domain>';
HttpClient client2 = new HttpClient()..badCertificateCallback = (_certificateCheck);
HttpClientRequest request = await client2.getUrl(Uri.parse(url));
var response = await request.close(); // sends the request
// transforms and prints the response
response.transform(Utf8Decoder()).listen(print);
This code showed a Error 404: Not found on the page that I need to get my JSON data from.
I also installed postman and checked my website with the GET statement for the same list of restaurants I try to retrieve in the flutter code posted above and see this:
Postman GET screenshot
Update 2:
So I configured SSL on my website and the problem still persists. I tried testing the GET request via postman and it returns a error 404 page as well. I have tried going through my server files and laravel logs and nothing did the trick.
Its as if my website cannot route to the specific pages in my API folder. BUt they are all defined in api.php.

google analytics apis not working in production

I am trying to use the google analytics apis v3 to embed the analytics graph to my website using Certificate file. I got it to work on the local machine but when I deploy the code to my web server it produces this error:
The remote server returned an error: (400) Bad Request.
Does anyone know what is causing this error message and why I can't get the google graph on my production website?
Here is the code that is working on my local machine:
string scope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue(),
x509Certificate2File = HttpContext.Current.Server.MapPath("~/App_Data/privatekey.p12"),
x509Certificate2FilePassword = "notasecret",
serviceAccountId = "xxxxxxx#developer.gserviceaccount.com",
profileId = "ga:xxxxxxxx",
startDate = "2013-10-06",
endDate = "2013-11-07";
AuthorizationServerDescription desc = GoogleAuthenticationServer.Description;
X509Certificate2 key = new X509Certificate2(x509Certificate2File, x509Certificate2FilePassword, X509KeyStorageFlags.Exportable);
AssertionFlowClient client = new AssertionFlowClient(desc, key) { ServiceAccountId = serviceAccountId, Scope = scope };
OAuth2Authenticator<AssertionFlowClient> auth = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);
AnalyticsService gas = new AnalyticsService(new BaseClientService.Initializer() { Authenticator = auth });
DataResource.GaResource.GetRequest request = gas.Data.Ga.Get(profileId, startDate, endDate, "ga:visits");
request.Dimensions = "ga:day";
request.MaxResults = 10;
/* error 400 occur here on the production */
Google.Apis.Analytics.v3.Data.GaData data = request.Execute();
Thanks
There is only one possibility and without looking at the code you're going to have to chase it down; one of the paths are wrong and needs to be changed. This could be in the form of an IP address as well when I say "path" as you are calling something that is not there. It worked fine on your local machine (correct path) and it gave a 400 on the remote one (bad request) as in calling the wrong place.

CRMService.asmx - 401 Unauthorized error

CRM Portal is setup on "crmstaging" machine, on port 5555.
Following is the path of CRM Service:
http://crmstaging:5555/MSCrmServices/2007/CrmService.asmx
I am creating an ASP.NET Website on my dev machine "crmdev", and have added reference of the above service.
Now, I am trying to use various methods of this service to perform operations on my CRM entities, for that, I have written following code in button click of the page:
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "MyCompany";
CrmService service = new CrmService();
service.CrmAuthenticationTokenValue = token;
service.Credentials = new System.Net.NetworkCredential("username","password","domainname");
//service.Credentials = System.Net.CredentialCache.DefaultCredentials;
string fetch1 = #"<fetch mapping=""logical"">
<entity name=""account"">
<all-attributes/>
</entity>
</fetch>";
String result1 = service.Fetch(fetch1);
txtBox1.Text = result1;
In above code, I have passed credentials of the user having access on CRM Staging machine.
While trying to execute this code, I get an error saying "401 Unauthorized".
How to resolve this issue?

Getting Google Oauth2 Token using dotnetopenauth

I'm having an issue retreiving the OAuth2 token for google using DotNetOpenAuth 4.2.0.13024.
I've got to the point where I can successfully make the authorization request to the google endpoint https://accounts.google.com/o/oauth2/auth
When the user clicks 'OK', google then calls my callback URL as expected with the appropriate "code" query string.
However, I am unable to exchange this code for a token, as my calls keep failing with "Protocol exception was unhandled" execption and "400 Bad request" as the inner exception. This is the code I am using to exchange the token
private static AuthorizationServerDescription authServerDescription = new AuthorizationServerDescription
{
TokenEndpoint = new Uri("https://accounts.google.com/o/oauth2/token"),
AuthorizationEndpoint = new Uri("https://accounts.google.com/o/oauth2/auth")
};
static GoogleContacts()
{
Client = new WebServerClient(authServerDescription, "{my_cliend_id}", "{me_secret_key}");
}
var authorization = Client.ProcessUserAuthorization(); // <- Exception is thrown here
if (authorization != null)
{
Authorization = authorization;
Response.Redirect(Request.Path); // get rid of the /?code= parameter
}
PS: it seems like a new version of DotNerOpenAuth has been released but, I am unable to get it because the zip download still points to the older version and Nuget keeps failing on me :(

Getting 400 Bad Request erro calling java web service

I am connecting to a java web service from my asp.net app ,but I am getting a 400 Bad request exception.
I have added a web reference in my project and using that to connect in the code as follows :
client is the web service reference object.
NetworkCredential credentials = new NetworkCredential("", "");
client.Credentials = credentials;
client.PreAuthenticate = true;
client.RequestEncoding = Encoding.UTF8;
object response = client.getmethod(req);
I also tried putting in
client.UnsafeAuthenticatedConnectionSharing = true;
client.AllowAutoRedirect = true;
but it still does not work and gives me the same error. The request is working if i try from Soap-UI from my machine.
To Add, I am getting a ClientProtocol error in SoapUI also if i don't select authentication type as "PreEmptive". Is there a way to set this in asp.net.
Any thoughts would be appreciated.

Resources