Logging to Splunk from AWS Lambda via NLog

First, it’s important to keep you Lambdas lean and mean as warm up times can be significant (in seconds!). Do not load unnecessary libraries like ASP.NET Core in your Lambda functions.

I’ll be showing how to use NLogTarget.Splunk package from NuGet (link).

Just like for any other type of app, you need an NLog.config file (see example here)

I strongly recommend you enable async logging in NLog.config via

targets async="true"

otherwise logging will be done synchronously, slowing down the execution time of your function.

To load NLog.config, do the following in the beginning of your function:

var logFactory = LogManager.LoadConfiguration("NLog.config");
var logger = logFactory.GetCurrentClassLogger();
// continue on using logger. LogManager.GetCurrentClassLogger() also works

NLog.config must be in your Lambda package, so ensure it’s copied there upon build (set it as “Content/Copy If Newer” in Visual Studio)

Prior to completing your Lambda’s execution, ensure you add

LogManager.Flush(new TimeSpan(0, 0, 3)); // flush any remaining messages. Max 3 seconds

This will allow NLog to “catch up” writing any outstanding log entries. If you have a global exception handler in your lambda function, make sure to add the same line there as well. If you do not — you may have a lambda that fails and no logs that are sent out.

That’s it. To learn more about using NLogTarget.Splunk, see documentation here

Getting ASP.NET Core Applications Production Ready in Elastic Beanstalk (IIS 10)

By default, there are several settings in IIS which would cause issues in Production for high-load applications.

(Steps below were tested on Win 2016, IIS 10, running ASP.NET Core 2.0.1 with .NET Framework 4.7.1)

Firstly, IIS is configured to shut down a process after x minutes of inactivity. The default setting is 20 minutes. The setting is called “Idle Time-Out (mintues)”.

In a web farm scenario, for one reason or another, you can have a node that did not receive a request in a span of 20 minutes. Once the node does receive the request, it will have to spin up the ASP.NET Core app, which takes some time. The user will then have to wait for the spin up to complete before receiving the response. This results in sub-ideal user experience.

To disable the timeout run this command:

(You can add these commands as .configs in your .ebextensions)

%systemroot%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.processModel.idleTimeout:00:00:00 /commit:apphost

Also, IIS will recycle an app pool after very 29 hours (1740 minutes). To disable the auto-recycle, run this command:

%systemroot%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.recycling.periodicRestart.time:00:00:00 /commit:apphost

Then, we need to set the start mode to “AlwaysRunning” instead of the default “OnDemand”

%systemroot%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.autoStart:"True" /commit:apphost

%systemroot%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.startMode:"AlwaysRunning" /commit:apphost

When deploying a new version of the app, IIS or ElasticBeanstalk will NOT automatically warm up or invoke your application. For this to happen you need to either automatically call each EC2 node and warm it up, or you can use IIS Application Initialization (https://docs.microsoft.com/en-us/iis/configuration/system.webserver/applicationinitialization/)

By default, EC2 nodes do not have this feature enabled. To enable the feature, install it via:

powershell.exe -Command "Install-WindowsFeature Web-AppInit"

Then, in you web.config, specify the path which should be called to warm up the application. In this example, warmup action is called on the Home controller.

<?xml version="1.0" encoding="utf-8"?>
       <add initializationPage="home/warmup" />

And here’s the controller/method:

public class HomeController : Controller
    public async Task Warmup()
        // do warmup
        // kick out requests not coming from or ::1

In the warmup method (action), I strongly recommend you check if the request is coming from ::1 or, and if it is not, disallow the warmup. This will prevent from someone doing a warmup (which is often expensive) without having the authorization to do so. Since the IIS Application Initialization module is doing the invocation of your warmup method, the request will come from

Lastly, you need to set “Preload Enabled” to “True” for all your sites via this command:

%systemroot%\system32\inetsrv\AppCmd.exe list app /xml | %windir%\system32\inetsrv\appcmd set app /in /preloadEnabled:True

And there you have it, your ASP.NET Core applications are now production ready!

Idea: Inconspicuous body cams for athletes

When watching a hockey game it would be cool if you can see the game from the point of view of the players. If one could design a small camera that is of no trouble to the wearer and that has great image quality then during the game the broadcaster can cut to any of those cameras to show a different angle.

If watching online, I could select the player from a list below the video player widget and watch the game from that player’s point of view.

Idea: Control (and rent) Drones Remotely

When travelling to Iceland and Khao Yai national park in Thailand I noticed an emerging trend: people bringing drones with them on a trip.

Drones are not cheap. They start at 1k USD plus a good camera will run you another grand, at least.

What if there was a way to remotely control a drone, that is rented? For example, one could establish a company that has several physical drones deployed in interesting parts of the world – could be national parks, nature reserves, near volcanoes, etc.

Then, via a website one can book a time slot to fly a drone in any of those locations. The flying time may be limited to 15 mins max, for example. After downloading the remote control app,  I can remotely fly a drone miles away in a different continent – in the comfort of my own home. I would pay premium for the experience.


Idea: Allow drones to recharge from power lines

There are miles and miles of high voltage power lines running all throughout Canada – from city to city and province to province. Wouldn’t it be cool if delivery drones and such had an ability to recharge by hovering and attaching a charge cable to an exposed high voltage power line. I’m sure the voltage / amperage can be stepped down to something that a drone can use.

Drones, when detecting low battery, would use a map to find the closest power line and then “sit” on a wire like a bird until recharged. This way travelling over longer distances problem can be solved.

Idea: Dual Exhaust – one for city and one for highway use

The main problem with “performance” or louder than stock exhausts is that they are annoying or no fun on the highway. Your throttle is pretty much constant on the highway and the elevated noise coming from the exhaust gets annoying quickly. You can sound proof your car but that can run you into $ 1k+ easily.

Another solution is to have two mufflers with an ability to choose though which one the exhaust gases will flow. One muffler can be louder so you can use it in the city. Once you go on the highway you can flip a switch and activate the quieter muffler.

A performance muffler is around $100. Plus piping – another $30 or so. The ability to switch between the two? Throw in another $100. Many sports cars or sporty looking cars come with dual mufflers anyhow. So it’s just adding the switch.

C# – Lookup nested field in ExpandoObject at runtime

say you have a JSON object like this

    home: {
        garage: {
            bike: {
                make: "honda"

in C# you’ve loaded the JSON into an ExpandoObject like this:

dynamic json = JsonConvert.DeserializeObject("json text above...");

to lookup a field, you can just do

var make = json.home.garage.bike.make; // "honda"

which is just great.

but what if you need to lookup fields whose names you do not know at compile time?

with the little helper i wrote you can do this:

var fieldName = "home.garage.bike.make"; // this will be resolved at runtime

var make = json.GetField(fieldName);


public static object GetField(this ExpandoObject expandoObject, string path)
    if (expandoObject == null)
        return null;

    var pathSegments = path.Split('.');
    var lastPathSegment = pathSegments[pathSegments.Length - 1];

    var cursor = (IDictionary)expandoObject;

    for (int i = 0; i < pathSegments.Length - 1; i++)
        var pathSegment = pathSegments[i];

        cursor = (IDictionary)cursor[pathSegment];

    object result = null;

    cursor.TryGetValue(lastPathSegment, out result);

    return result;