Generally it is useful to use logging on different levels and enable/disable the levels as needed. There might be no need to see any informational messages in certain applications until there is a certain error that you want to inspect. In other cases it might be useful to see verbose things like "user x did action y" all the time. As a rule of thumb I would only log things to which I had a specific use-case in mind or things I knew from experience that they help down the line. Regarding if logging should be done in general: Yes, please. As someone who writes and uses tools that go through logs all the time I am very grateful for applications that log well - meaning not too much, but at least all errors and warnings. If you use Windows then you could think about writing events to an eventlog instead of writing text files tho.
Johannes B Latzel
Posts
-
is NLog still popular? -
running Powershell from ASP.NET Core 6I'm running an ASP.NET Core 6 application on an IIS as a Rest Api calling Powershell scripts for specific tasks. It works well from my laptop (Windows 10) but doesn't work when I'm running it on a Windows Server 2019 Version 1809 Build 17763.1935. The error tells me that it cannnot find the assembly "Microsoft.Management.Infrastructure". Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Das System kann die angegebene Datei nicht finden. File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' "Das System kann die angegebene Datei nicht finden." = "File not found." Did anyone encounter that problem too? The server has the following things installed: Microsoft .NET 6.0.3 - Windows Server Hosting Microsoft .NET Runtime - 6.0.3 (x64) Microsoft .NET Runtime - 6.0.3 (x86) Microsoft .NET SDK 6.0.201 (x64) Microsoft ASP.NET Core 6.0.3 - Shared Framework (x64) Microsoft ASP.NET Core 6.0.3 - Shared Framework (x86) Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.28.29913 Microsoft Visual C++ 2015-2019 Redistributable (x86) - 14.28.29913 IIS 10.0 Windows PowerShell 5.1 PowerShell 7.2.1 Now to test if it is the server setup missing something I wrote a little .net console application with this code
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using Microsoft.PowerShell;var initialSessionState = InitialSessionState.CreateDefault();
initialSessionState.ExecutionPolicy = ExecutionPolicy.Unrestricted;
using (PowerShell powerShell = PowerShell.Create(initialSessionState))
{
powerShell.AddCommand("whoami");
foreach (var item in powerShell.Invoke())
{
Console.WriteLine(item.BaseObject.ToString());
}
if (powerShell.HadErrors)
{
throw new Exception("powershell script had errors");
}
}I can run this program on the server without problems. But if I copy-paste this exact code into my Api code it fails with the above error. Any ideas?
-
Multiple Windows DomainsYou could use trusts between those domains to enable your "normal" user to be able to do stuff on the developement and UAT domain, but tbh working on different domains just sucks. It adds a lot of overhead so there has to be a really good reason to go through that kind of trouble. Until now I have only seen different domains trusting each other in cases of different companies working together in some sort. I also saw people having multiple devices to work on different domains but that sucks a lot too. Imagine carrying 2 laptops with you all the time.. or in your case: 3. What you could do is set up several computers in the dev and uat domain and login on those devices via RDP using users from those respective domains. But that's all meh.