If you are not using the seri log configuration package and want to set up serilog based on app specific configuration use
webHostBuilder.ConfigureLogging((hostingcontext, logging) =>
{
var logSettings = new LogConfiguration();
//my custom section
hostingcontext.Configuration.GetSection("LogSettings").Bind(logSettings);
if (logSettings.Sink.Equals("rollingFile"))
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", Information)
.Enrich.FromLogContext()
.WriteTo.RollingFile(logSettings.Url)
.CreateLogger();
}
else
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", Information)
.Enrich.FromLogContext()
.WriteTo.Seq(logSettings.Url)
.CreateLogger();
}
var levelSwitch = new LoggingLevelSwitch();
int.TryParse(logSettings.LogLevel, out var level);
levelSwitch.MinimumLevel = (LogEventLevel)level;
logging.AddSerilog(dispose: true);
});
I’m not a nerd!! But I love to learn technology. Have a good collection of tech book soft copies, hardly read. Always bing to solve problem. Now decided to scribble - whatever I binged for my tech work!!!! Disclaimer: This is not my view ;) itz collated views
Thursday, February 22, 2018
Autofac dependency injection per request based on header parameter ASP.NET Core2.0
builder.Register(c =>
{
string dependencyName= c.Resolve<IHttpContextAccessor>().HttpContext.Request.Headers[Constants.CountryHeader];
return c.ResolveNamed<interface>(dependencyName);
}).InstancePerLifetimeScope();
and in the module
protected override void Load(ContainerBuilder builder)
{
//register modules here
builder.RegisterType<ClassName>().Named<Interfacer>("Name of dependency");
}
{
string dependencyName= c.Resolve<IHttpContextAccessor>().HttpContext.Request.Headers[Constants.CountryHeader];
return c.ResolveNamed<interface>(dependencyName);
}).InstancePerLifetimeScope();
and in the module
protected override void Load(ContainerBuilder builder)
{
//register modules here
builder.RegisterType<ClassName>().Named<Interfacer>("Name of dependency");
}
Monday, December 11, 2017
API Dev Ex Journey
When
I had a chit chat with the business I'm working with, they told me often they see a lot of fraud
transactions originating from one of the their eCommerce B2C web sites. Most of the fraud transactions exhibit a pattern – either billing address or shipping address is invalid. The eCommerce site doesn’t implement an address validation for billing or shipping address. If the
validations do exist, without correcting the address issues a user cannot
navigate to the payment page. So, I looked at some of the address validation
services. As a developer what I did is relevant for any API seekers J
1.
Searchability/Discoverability
of an API
As
the first step, a developer MUST go to any available search engines and hunt
for an API they are interested in. So, if we are doing any commercial APIS,
it’s very important to make sure that the APIS are ranked properly by the
search engines and it MUST bubble up when a user search for any API related key
words.
2.
API
documentation
After
the API hunt, I found a lot of companies, UPS, USPS, Experian, Smart streets
offer address validation service. Various criterions I used to weigh the API
offerings from different companies are:
1.
How
easy and fast I can apprehend the APIs
2.
Simplicity
of API methods, request and response – From smarty street, most of the APIS,
request and response object are self-explanatory. I don’t even go through
their API documentationsJ - I think the APIs
directly talk with the developer.
3.
Try
it yourself – After reading the APIs, the immediate step a developer took is to
see the APIs in action. Some API providers provide a try it now link
that allows a user to test the APIs without logging in or without even
request for an API key.
Able to try out an API without logging in or providing 100 steps of information is another key aspect of Dx.
Able to try out an API without logging in or providing 100 steps of information is another key aspect of Dx.
3.
Integration
Another
criteria I considered is how easily I can integrate the APIs to my application.
For this, I look for any SDKs available from the API provider. Most of the
companies provides SDK that supports various programming languages.
Another aspect I considered is, how often the APIs are versioned and how
often the companies publish their SDKs.
Other
aspects like, cost of usage (fixed vs pay per use), support …etc are
considered. However, I wish to share the above three core aspects. Please share
your thoughts?
Tuesday, June 20, 2017
Get Solarized
I was watching Scott Hanselman and Maria's MVA course and Scott's command prompt looks eye catchy and later I've read his blog on getting solarized.
https://www.hanselman.com/blog/GetSolarizedAwesomeCommandPromptColorsForVSVSCodeCmdPowerShellAndMore.aspx
If you prefer an awesome command prompt, VS code or VS, refer his blog. In short:
For command prompt, I downloaded the package and installed the dark theme
regedit /s solarized-dark.reg
VS code was pretty easy
Short cut for Theme - Ctrl +K, Crtl +T and select solarized theme
Visual Studio Console:
Refer - https://github.com/leddt/visualstudio-colors-solarized
https://www.hanselman.com/blog/GetSolarizedAwesomeCommandPromptColorsForVSVSCodeCmdPowerShellAndMore.aspx
If you prefer an awesome command prompt, VS code or VS, refer his blog. In short:
For command prompt, I downloaded the package and installed the dark theme
regedit /s solarized-dark.reg
VS code was pretty easy
Short cut for Theme - Ctrl +K, Crtl +T and select solarized theme
Visual Studio Console:
Refer - https://github.com/leddt/visualstudio-colors-solarized
Thursday, May 18, 2017
Man in the Middle Attack (MitM) Troy Hunt webinar
Great talk, explained why companies need to plan to use HTTPS (TLS use interchangeably :))
- MitM attack from the router, ISP.
- Content injection on an insecure page (HTTP)
- HTTP2 works with TLS. H2 protocol loads resources very fast (httpvshttps.com)
- All major browsers are planning to show warning, not secure on form fields, that will scare the end customer away from using the websites.
- chrome://flags/ - you can change settings to explicitly show when a connection is not secure
- Trust on First use (TOFU) problem
- Add secure header, set the max age, include sub domains, preload hsts
- hstspreload.org - registering HSTS, refer submission requirements
Thursday, April 27, 2017
Dream and project
I read an interesting article about dreams. From wiki - A dream is a succession of images, ideas, emotions, and sensations that usually occur involuntarily in the mind during certain stages of sleep.
Most of the IT projects are a result of a dream, an idea. A dream occur in the REM stage of the sleep and it lasts for a few seconds or minutes. During a dream, I can watch a full length colorful movie, Avatar, in a few seconds. In reality, Avtar took 10 years to make - http://tech.firstpost.com/news-analysis/avatar-took-10-years-to-make-we-wonder-why-12779.html
As I mentioned any projects are a result of a dream. To materialize the dream, it takes considerable effort and time, else the dream turns into a failed project.
In my experiences, the team wants to execute the ideas as they see in their dreams and the best way to execute is "Agile". I don’t complain agile is wrong, you need some discipline while doing agile projects, may be Disciplined Agile Development (big fan of it). However, the team usually forget the time and effort needed to plan the project - drafting a proper screen play, identify the right actors, actresses, technicians, the locations.......
I had worked in a project where the team wants to build a cool idea, so the business said (directed) - let’s use this vendor, let’s use this component and let’s integrate things together. End of the story, the vendor never understood what they are building, the internal team never analyzed what's the external provider offers and the one month project (integration of components) took three months and I don't know whether the project is materialized. I forgot to mention, there is another team who does UI :) and if you ask anyone what they are trying to achieve, you will get different opinions and the only person who knows the end goal is the "test lead" for that project.
So, bottom line is - dream takes a few seconds to minutes. A successful project needs right vision, right people, proper planning and a good team attitude :)
Wednesday, April 26, 2017
Create a meeting by using the EWS Managed API
Our team has used EWS API's Appointment service to book a meeting room. During our testing, its been noted that the room was not blocked on the exchange server and over lapping meetings can be booked for that room.
I had gone through the code and found that the meeting room was added as part of the required attendees list
meeting.RequiredAttendees.Add("roomid@contoso.com");
In this case, the room has to accept the request so as to get the calendar blocked. The MSDN document didn't give any clue to add a meeting room. It specifies a "Location" field, however it wont block the meeting room for the specified time range.
https://msdn.microsoft.com/en-us/library/office/dn495611(v=exchg.150).aspx
After a few trail and error, we found that, the meeting room must be added as part of the resources
meeting.Location = "Location name";
meeting.Resources.Add("roomid@contoso.com");
Updated Code - assuming an exchange service object has been created:
I had gone through the code and found that the meeting room was added as part of the required attendees list
meeting.RequiredAttendees.Add("roomid@contoso.com");
In this case, the room has to accept the request so as to get the calendar blocked. The MSDN document didn't give any clue to add a meeting room. It specifies a "Location" field, however it wont block the meeting room for the specified time range.
https://msdn.microsoft.com/en-us/library/office/dn495611(v=exchg.150).aspx
After a few trail and error, we found that, the meeting room must be added as part of the resources
meeting.Location = "Location name";
meeting.Resources.Add("roomid@contoso.com");
Updated Code - assuming an exchange service object has been created:
Appointment meeting = new Appointment(service); // Set the properties on the meeting object to create the meeting. meeting.Subject = "Team building exercise"; meeting.Body = "Let's learn to really work as a team and then have lunch!"; meeting.Start = DateTime.Now.AddDays(2); meeting.End = meeting.Start.AddHours(4); meeting.Location = "Conference Room 12";
meeting.Resources.Add("ConferenceRoom12@contoso.com");
meeting.RequiredAttendees.Add("Mack@contoso.com"); meeting.RequiredAttendees.Add("Sadie@contoso.com"); meeting.OptionalAttendees.Add("Magdalena@contoso.com"); meeting.ReminderMinutesBeforeStart = 60; // Save the meeting to the Calendar folder and send the meeting request. meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy);
Subscribe to:
Posts (Atom)
Featured post
How to connect to Mongo Atlas from Robo 3T
If you use a local instance of MongoDB, you might be a great fan of Robo3T. However, if you are using Mongo Atlas, the Atlas web interface p...
Popular Posts
-
Last week I was working on on-boarding a few SAP Odata APIs to API Management gateway. The APIM tool used by my organization supports JSON ...
-
If you use a local instance of MongoDB, you might be a great fan of Robo3T. However, if you are using Mongo Atlas, the Atlas web interface p...
-
My journey towards AZ solution architect needs more hands own with Linux. So, today (still on PTO and recovering from a medical procedure) I...