aspnetcore
ASP.NET Core OpenTelemetry Logging
·361 words·2 mins
dotnet
opentelemetry
aspnetcore
As you may know I’ve been collaborating with Dapr and I’ve learned that one of the things it enables you to do is to collect traces with the use of the OpenTelemetry Collector and push the events to Azure Application Insights.
After some reading I went and check if I could also write my ASP.NET Core applications to log using the OpenTelemetry Log and Event record definition:
Scale a Kubernetes Deployment with .NET Core
·351 words·2 mins
dotnet
kubernetes
devops
aspnetcore
Let’s start:
Create a folder for your new project # Open a command prompt an run:
mkdir kuberenetes.scale Create the project # cd kuberenetes.scale dotnet new api Add the references to KubernetesClient # dotnet add package KubernetesClient -v 1.5.18 dotnet restore Create a PodsController.cs with the following code # using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using k8s; using k8s.Models; using Microsoft.AspNetCore.JsonPatch; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; namespace kubernetes.scale { [Route("api/[controller]")] [ApiController] public class PodsController : ControllerBase { private KubernetesClientConfiguration k8sConfig = null; public PodsController(IConfiguration config) { // Reading configuration to know if running inside a cluster or in local mode. var useKubeConfig = bool.Parse(config["UseKubeConfig"]); if (!useKubeConfig) { // Running inside a k8s cluser k8sConfig = KubernetesClientConfiguration.InClusterConfig(); } else { // Running on dev machine k8sConfig = KubernetesClientConfiguration.BuildConfigFromConfigFile(); } } [HttpPatch("scale")] public IActionResult Scale([FromBody]ReplicaRequest request) { // Use the config object to create a client. using (var client = new Kubernetes(k8sConfig)) { // Create a json patch for the replicas var jsonPatch = new JsonPatchDocument<V1Scale>(); // Set the new number of repplcias jsonPatch.Replace(e => e.Spec.Replicas, request.Replicas); // Creat the patch var patch = new V1Patch(jsonPatch); // Patch the "minions" Deployment in the "default" namespace client.PatchNamespacedDeploymentScale(patch, request.Deployment, request.Namespace); return NoContent(); } } } public class ReplicaRequest { public string Deployment { get; set; } public string Namespace { get; set; } public int Replicas { get; set; } } } Replace the contents of the appsettings.Development.json file # Note the UseKubeConfig property is set to true.
Updated Step by step: Serilog with ASP.NET Core
·276 words·2 mins
dotnet
aspnetcore
serilog
Many of you come to my site to read the post Step by step: Serilog with ASP.NET Core which I wrote in 2016 and is completely out of date, so with this post I will show you how to setup Serilog to work with your ASP.NET Core 2.2 applications.
Create an ASP.NET Core project # md aspnet.serilog.sample cd aspnet.serilog.sample dotnet new mvc Add the following dependencies to your project # dotnet add package Serilog.AspNetCore dotnet add package Serilog.Extensions.Logging dotnet add package Serilog.Sinks.ColoredConsole Change your Program.cs file to look like the following # using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Serilog; using Serilog.Core; using Serilog.Events; namespace aspnet.serilog.sample { public class Program { public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .MinimumLevel.Debug() .WriteTo.ColoredConsole( LogEventLevel.Verbose, "{NewLine}{Timestamp:HH:mm:ss} [{Level}] ({CorrelationToken}) {Message}{NewLine}{Exception}") .CreateLogger(); try { CreateWebHostBuilder(args).Build().Run(); } finally { Log.CloseAndFlush(); } } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseSerilog() .UseStartup<Startup>(); } } Inject the logger to your services or controllers # Change the home controller and log some actions:
Develop and build ASP.NET Core applications to run on Kubernetes with Draft
·385 words·2 mins
dotnet
kubernetes
azure
aks
azure container registry
aspnetcore
You start developing an ASP.NET Core application to run it in Kubernetes and suddenly you find yourself creating a docker file, building an image, pushing the image to a registry, creating both a deployment and a service definition for Kubernetes and you wonder if there is a tool out there to help you streamline the whole process.
Revisiting Docker Multi Stage Builds to build an ASP.NET Core Echo Server
·252 words·2 mins
dotnet
aspnetcore
docker
On April I wrote a post about Using Docker Multi Stage Builds to build an ASP.NET Core Echo Server and these days while preparing a talk, on CI/CD and kubernetes, I started to play with the simple sample I wrote back then.
Soon enough I noticed that with each docker build command I issued the dependencies for the echoserver were always restored, even if no changes were made to the project file (csproj).
Using Docker Multi Stage Builds to build an ASP.NET Core Echo Server
·390 words·2 mins
dotnet
aspnetcore
docker
Today I’ll show you how to create a simple Echo Server with ASP.NET Core and then a Docker Image using multi-stage build:
Create the Application # Open a PowerShell promt and run:
mkdir echoserver cd echoserver dotnet new console dotnet add package Microsoft.AspNetCore -v 2.0.2 Replace the contents of Program.cs # Replace the contents of the Program.cs file with the following code:
Toggle Raspberry Pi GPIO Pins with ASP.NET Core 2.0
·298 words·2 mins
dotnet
aspnetcore
raspberry pi
Today I’ll show you how to Toggle Raspberry Pi GPIO Pins with ASP.NET Core 2.0.
First be aware of the following prerequisites:
.NET Core 2.0 SDK A Raspberry Pi 3 Running Raspbian Install linux dependencies: sudo apt-get install curl libunwind8 gettext Now let’s start:
Create a folder for your new project # Open a command prompt an run:
Run ASP.NET Core on OpenShift
·443 words·3 mins
dotnet
aspnetcore
docker
openshift
Today I’ll show you how to Run ASP.NET Core on OpenShift.
First be aware of the following prerequisites:
You’ll need a working Docker installation. If you are using Windows 10 you can get Docker for Windows here. Be sure to Disable TLS for 127.0.0.1:2375 for your Docker installation Be sure to set 172.30.0.0/16 as an Insecure Registry in your Docker installation Be sure to set 172.30.1.1:5000 as a Registry Mirror in your Docker installation You’ll need download the oc Client Tools Note: If you want to learn about OpenShift and what can you do with it, I recommend the free book: Openshift for Developers.
Deploy your ASP.NET Core Web API to AWS Lambda
·832 words·4 mins
dotnet
aspnetcore
aws
serverless
Today I’ll show you how to Deploy your ASP.NET Core Web API to AWS Lambda.
First be aware of the following prerequisites:
You’ll need an AWS account: https://aws.amazon.com/ You’ll need AWS CLI installed: http://docs.aws.amazon.com/cli/latest/userguide/installing.html You’ll need your AWS security credentials Some basic knowledge on AWS Stacks, API Gateway, Lambda and Buckets Now let’s start:
Create a folder for your new project # Open a command promt an run
Start with Elasticssearch, Kibana and ASP.NET Core
·398 words·2 mins
dotnet
aspnetcore
docker
elastic search
kibana
serilog
You want to Start with Elasticssearch, Kibana and ASP.NET Core and also want to do it fast? Let’s use Docker and find out how easy it can be:
Create a folder for your new project # Open a command prompt an run
Raspberry Pi: Run ASP.NET Core on Startup
·195 words·1 min
dotnet
aspnetcore
powershell
raspberry pi
Last week I wrote: Step by step: Running ASP.NET Core on Raspberry Pi and didn’t have the time to write about running the application on startup.
After browsing for a while I found this great post: Windows IoT Core: Running a PowerShell Script on Startup which showed me the way!
As a prerequisite read and run the sample provided here: Step by step: Running ASP.NET Core on Raspberry Pi
Step by step: Running ASP.NET Core on Raspberry Pi
·428 words·3 mins
dotnet
aspnetcore
raspberry pi
After reading .NET Core on Raspberry Pi and successfully running a console application on Windows 10 IoT Core on my Raspberry Pi 3 I decided to write: Step by step: Running ASP.NET Core on Raspberry Pi.
First be aware of the following prerequisites:
Windows 10 IoT Core I’m running Insider Preview v.10.0.15058.0 .NET Core 2.0 SDK Now let’s start:
.Net Core and NancyFX: can writing a WebApi get any simpler?
·581 words·3 mins
dotnet
aspnetcore
nancyfx
Last Thursday I attended a Meetup hosted by my friends of @MsCodersMadrid in Madrid where, thanks to @snavarropino, I learned a bit about the NancyFX open source framework.
I really couldn’t believe my eyes when I saw how simple it is to use NancyFX to write a Web API. Two of the things that got my attention were: the out of the box content negotiation and zero configuration dependency injection.
Debug ASP.NET Core on Docker with Visual Studio Code
·455 words·3 mins
devops
dotnet
aspnetcore
debugging
visual studio code
Last Thursday I started reading the Free eBook: “Containerized Docker Application Lifecycle with Microsoft Tools and Platform” by Cesar de la Torre. The book is really easy to read and really gives the reader a glimpse on the way to approach the overall application lifecycle when using containers and Microsoft Technologies. One of the interesting things he mentions is the ability to debug your source code inside a container using Visual Studio or Visual Studio Code, so I decided to try it out and Debug ASP.NET Core on Docker with Visual Studio Code
Step by step: Expose ASP.NET Core over HTTPS with Docker
·442 words·3 mins
azure
dotnet
aspnetcore
docker
https
Kestrel
openssl
This week I decided to modify the sample of my previous post: Step by step: Scale ASP.NET Core with Docker Swarm so you can add TLS to your ASP.NET Core applications and Dockerize it.
Let’s see how I changed the application in order to make it work:
Add HTTPS support for Kestrel # I added the following line to the dependencies in the project.json file.
Step by step: Scale ASP.NET Core with Docker Swarm
·388 words·2 mins
azure
dotnet
aspnetcore
docker
A few weeks ago I posted Step by step: ASP.NET Core on Docker were I showed how to build and run a Docker image with an ASP.NET Core application.
Today I bring you: Step by step: Scale ASP.NET Core with Docker Swarm so you can scale out or in the same application.
Assuming you have Docker 1.12 or later installed and running, follow this steps:
Step by step: ASP.NET Core on Docker
·287 words·2 mins
azure
dotnet
aspnetcore
docker
This week I have to give an introductory talk on DevOps and Docker and therefore I decided to prepare a simple Step by step: ASP.NET Core on Docker sample.
Assuming you have Docker installed and running, follow these 4 simple steps:
Create a dockerfile # On your Docker box create a dockerfile with the following contents
Step by step: Serilog with ASP.NET Core
·256 words·2 mins
dotnet
aspnetcore
NOTE: This post is out of date. Please read: Updated Step by step: Serilog with ASP.NET Core for an update. # Last week I wrote about .NET Core and Microsoft Bot Framework and I’m still learning and playing with it. The thing is that once I implemented more features and deployed the bot to Azure it didn’t work. So I had to find a way to log and trace what was happening in order to diagnose and fix the problem.
.NET Core and Microsoft Bot Framework
·782 words·4 mins
dotnet
aspnetcore
bot framewok
Today I’ll show you how to create a simple Skype bot that will reply with the same text message you send to it.
You’ll be using .Net Core and Microsoft Bot Framework. As you already know not every library has been ported to .Net Core so you’ll have to use the Microsoft Bot Connector API – v3.0 to bring the bot to life.
Add Swagger to your .NET Core Web API
·195 words·1 min
dotnet
aspnetcore
swagger
Last week .NET Core was released, and the first thing I tried to solve was how to Add Swagger to your .NET Core Web API:
Dependencies # At the time of writing you should add the following dependency to your project.json file