Principal Software Engineer at Allscipts in Malvern, Pennsylvania, Microsoft Windows Dev MVP, Husband, Dad and Geek.
51814 stories
·
22 followers

Avoiding the Debugger with Better Logging

1 Share

There's actually two reasons why I tend to avoid using debuggers. The first reason is a genuine belief that debuggers encourage short term thinking and quick fixes in software. The second reason is the terrible sights and sounds I witness when I launch a debugger like the VS debugger. It is the noise of combustion and heavy gears engaging. My window arrangement shatters and the work space transforms into a day-trading app with real time graphs and event tickers. A modal dialog pops up and tells me a thread was caught inside the reverse flux capacitor and allowed to execute freely with side-effects. I don't know what any of this means or has to do with finding my off-by-one error, which only adds to my sense of fear and confusion.

One way I avoid the debugger is by adding better logging to my software. The best time to think about what you need to log is when the software is misbehaving, and ideally before the software misbehaves in front of strangers. Sometimes the logging becomes verbose.

logger.Verbose($"ABBREVIATIONS");;
for (var index = ABBRSTART; index <= ABBREND; index++)
{
    for (var number = 0; number < NUMABBR; number++)
    {
        var offset = (NUMABBR * (index - 1)) + (WORDSIZE * 2);
        logger.Verbose($"For [{index}][{number}] the offset is {offset}");

        var ppAbbreviation = machine.Memory.WordAt(Header.ABBREVIATIONS);
        logger.Verbose($"For [{index}][{number}] the ppointer is {ppAbbreviation:X}");

        var pAbbreviation = machine.Memory.WordAddressAt(ppAbbreviation + offset);
        logger.Verbose($"For [{index}][{number}] the pointer is {pAbbreviation:X}");

        var location = machine.Memory.SpanAt(pAbbreviation);
        var result = decoder.Decode(location).Text;

        logger.Verbose($"Abbreviation [{index}][{number}] : {result}");
    }
}

Verbosity works well if you categorize correctly. Again, the best proving ground for a logging strategy is when the software is misbehaving. You can learn what knobs you need to tweak and what categories work well. With Serilog, which I still prefer, you can set the category to match type names in your software, then configure the log messages you want to see using code or configuration files.

public ILogger CreateLogger()
{
    var logger = new LoggerConfiguration()
        .MinimumLevel.Warning()
        .MinimumLevel.Override(typeof(FrameCollection).FullName, LogEventLevel.Verbose)
        .MinimumLevel.Override(typeof(Machine).FullName, LogEventLevel.Verbose)
        .MinimumLevel.Override(typeof(DebugOutputStream).FullName, LogEventLevel.Verbose)
        .MinimumLevel.Override(typeof(Instruction).FullName, LogEventLevel.Verbose)
        .MinimumLevel.Override(typeof(ZStringDecoder).FullName, LogEventLevel.Verbose)
        .Enrich.FromLogContext()
        .WriteTo.File(@"trace.log",
                      outputTemplate: "{SourceContext:lj}\n{Message:lj}{NewLine}{Exception}")
        .CreateLogger();
    return logger;
}

When is Visual Studio Not an Editor?

To use logs during test runs you need to sink log events into XUnit's ITestOutputHelper. The logs are available from the VS test runner by clicking on an "Open additional output for this result" link.

For one particular integration style test I have, the logs can get lengthy, which leads to an amusing message from VS.

Open an editor

An editor like Notepad? Am I not already in a piece of software that can edit text? It's like having the GPS in a Tesla tell me I'll need to use a 1988 Oldsmobile to reach my destination.

Read the whole story
alvinashcraft
1 minute ago
reply
West Grove, PA
Share this story
Delete

Selective Projects Loading using Solution Filter in Visual Studio

1 Share

Solution Filter in Visual Studio allows a faster load of the solution with selective projects. When we are working on a large solution with several projects, we may not work with all the projects together. Sometimes, specific developers only focus on a set of projects. Solution Filter in Visual Studio allows us to select only the required projects… Read More »

The post Selective Projects Loading using Solution Filter in Visual Studio appeared first on Daily .NET Tips.

Read the whole story
alvinashcraft
9 hours ago
reply
West Grove, PA
Share this story
Delete

Christian Geuer Pollmann on Erlang and Elixir

1 Share

Episode 594

Christian Geuer Pollmann on Erlang and Elixir

Christian Geuer-Pollmann describes the Erlang ecosystem, the Elixir language, and open source Azure tools he has built with Elixir.

Links:

https://github.com/chgeuer
https://twitter.com/chgeuer
http://blog.geuer-pollmann.de

Read the whole story
alvinashcraft
9 hours ago
reply
West Grove, PA
Share this story
Delete

#475 – An Interview with Christina Cyr

1 Share

Welcome Christina Cyr, CEO of dToor and the Cyrcle Phone





Download audio: http://traffic.libsyn.com/theamphour/TheAmpHour-475-ChristinaCyr.mp3
Read the whole story
alvinashcraft
9 hours ago
reply
West Grove, PA
Share this story
Delete

10 Important Git Commands that Every Developer Should Know

1 Share
Git is an important part of daily programming (especially if you're working with a team) and is widely used in the software industry. Since there are many various commands to use, mastering Git takes time but some commands are being used more frequently (mostly daily) and in this post, I

Read the whole story
alvinashcraft
11 hours ago
reply
West Grove, PA
Share this story
Delete

Kubernetes testing with KIND

2 Shares

Kubernetes in Docker (KIND)

There are many solutions for creating a local test Kubernetes environment, such as minikube or MicroK8s, but a new project called KIND offers a fresh approach that may interest Kubernetes developers and administrators.

KIND stands for Kubernetes IN Docker, and as the name suggests, it creates a Kubernetes cluster using Docker to host the nodes. This is a novel approach, that takes advantage of Docker’s easy, self-contained deployments and cleanup to create the test Kubernetes infrastructure.

KIND Installation

Make sure you have Docker and Go installed, and then install KIND with the command:

GO111MODULE="on" go get sigs.k8s.io/kind@v0.6.1

This will place the kind executable in the directory $GOPATH/bin/kind, which will be ~/go/bin/kind by default.

Assuming the Go bin directory is in the PATH, build a test cluster with the command:

kind create cluster --name mycluster

The first cluster takes a little while to download KIND Docker images, although subsequent clusters take less than a minute to create.

KIND will add the new cluster details as a context to your ~/.kube/config file, so you can test the cluster is up and running with the command:

kubectl cluster-info --context kind-mycluster

You can set this context as the default with the command:

kubectl config use-context kind-mycluster

Using the KIND Kubernetes cluster

The most immediate issue I ran into when using KIND was accessing the services deployed to the cluster.

By default KIND only exposes the Kubernetes API server. This means kubectl will work as expected. So you can deploy to the cluster and query resources, but accessing your services requires some extra work.

A solution is to use kubectl as a proxy:

kubectl proxy --port=8080

Kubernetes services are then available through a specifically formed URL like http://localhost:8080/api/v1/namespaces/default/services/webserver:http-web/proxy/.

The Kubernetes documentation has more details on these proxy URLs:

To create proxy URLs that include service endpoints, suffixes, and parameters, you simply append to the service’s proxy URL: http://kubernetes_master_address/api/v1/namespaces/namespace_name/services/[https:]service_name[:port_name]/proxy

Port forwarding removes the need to construct special URLs. Start port forwarding with a command like:

kubectl port-forward svc/webserver 8081:80

The service is now available on the local port of 8081, directing traffic to the service port 80. This means the URL http://localhost:8081 can be used to access the service.

You can also use port forwarding on an ingress controller:

kubectl port-forward svc/nginx-release-nginx-ingress 8081:80

This command allows you to access services via any ingress rules you have configured.

The KIND documentation also provides some additional details on how to expose ingress controllers for a more permanent solution.

First impressions

Once I got around the issue of accessing my services, KIND performed remarkably well for a beta release. External tools like Helm worked fine, and I could deploy custom dashboards to the cluster.

I appreciated the fact the KIND was so self-contained. Because everything is a Docker container, creating the cluster was quick, and when it was cleaned up afterward there was nothing left running on the system.

Conclusion

Getting a Kubernetes cluster running locally isn’t that difficult these days, but KIND makes it especially easy to create a cluster. Admittedly, Kubernetes running on Docker to orchestrate Docker is a little mind bending, but it can’t be beaten for convenience.

The real value of KIND is the ability to run it as part of automated tests. I didn’t have a use case for this personally, but I’m sure it lives up to the promise.

I’ll seriously consider using KIND over minikube for local testing from now on.

Read the whole story
sbanwart
9 hours ago
reply
Akron, OH
alvinashcraft
11 hours ago
reply
West Grove, PA
Share this story
Delete
Next Page of Stories