[.NET Core] Easy logging with log4net

Logging what’s happening in your application is something necessary and useful for your debugging sessions. As .NET Core is a fair new technology, you’re going to find a lot of guides on how to configure log4net for a .NET Framework application but it’s far less clearer for a .NET Core one.

In this guide, we’re going to create a new solution with multiple projects that will use our logging object. The goal is to never depend from the log4net package in any project but, instead, to depend on a local solution that will present a Logger object with static methods to log. Thus, we will only have to add an using and to call Logger.Log() to log something.

The simpler, the better, huh? Let’s go!

You’ll be able to download the example solution at the end of this guide! 😊

Read More

[Windows] Run elevated CMD as another user

Sometimes, you need to execute some commands as another user but while keeping administrator privileges. This can be useful if you manage a Windows Server, for example.

To do this, simply follow these steps:

  • Run a CMD with administrator privileges
  • Type runas /netonly /user:DOMAIN\USERNAME cmd (Replace DOMAIN\USERNAME with the targeted user values)

Windows will ask you the user password then will launch a new CMD window that has the administrator privileges while using the other user account:

Example using Powershell instead of CMD:

As you see, it does work too with Powershell. This means that if you want to launch Notepad instead of CMD or Powershell, you can do it too!