.net-core

Why FileSystemWatcher doesn't work in Linux container watching Windows volume

青春壹個敷衍的年華 提交于 2021-01-20 16:57:12
问题 Given the program: using System; using System.IO; namespace fsw_bug_poc { class Program { private static FileSystemWatcher _fileSystemWatcher; static void Main(string[] args) { _fileSystemWatcher = new FileSystemWatcher("Watched", "*.*"); _fileSystemWatcher.Changed += Notify; _fileSystemWatcher.Created += Notify; _fileSystemWatcher.Deleted += Notify; _fileSystemWatcher.Renamed += Notify; _fileSystemWatcher.IncludeSubdirectories = true; _fileSystemWatcher.EnableRaisingEvents = true; Console

Why FileSystemWatcher doesn't work in Linux container watching Windows volume

…衆ロ難τιáo~ 提交于 2021-01-20 16:56:25
问题 Given the program: using System; using System.IO; namespace fsw_bug_poc { class Program { private static FileSystemWatcher _fileSystemWatcher; static void Main(string[] args) { _fileSystemWatcher = new FileSystemWatcher("Watched", "*.*"); _fileSystemWatcher.Changed += Notify; _fileSystemWatcher.Created += Notify; _fileSystemWatcher.Deleted += Notify; _fileSystemWatcher.Renamed += Notify; _fileSystemWatcher.IncludeSubdirectories = true; _fileSystemWatcher.EnableRaisingEvents = true; Console

How can I configure NLog in .NET Core with appsettings.json instead of an nlog.config file?

六月ゝ 毕业季﹏ 提交于 2021-01-20 16:42:35
问题 The NLog documentation explains how to configure NLog for .NET Core applications by using an nlog.config XML file. However, I'd prefer to have just one configuration file for my application - appsettings.json . For .NET Framework apps, it's possible to put the NLog configuration in app.config or web.config . Is it possible to put the NLog config in appsettings.json in the same way? For example, how could I put this configuration example from the NLog documentation for ASP.NET Core 2 into

How can I configure NLog in .NET Core with appsettings.json instead of an nlog.config file?

五迷三道 提交于 2021-01-20 16:41:18
问题 The NLog documentation explains how to configure NLog for .NET Core applications by using an nlog.config XML file. However, I'd prefer to have just one configuration file for my application - appsettings.json . For .NET Framework apps, it's possible to put the NLog configuration in app.config or web.config . Is it possible to put the NLog config in appsettings.json in the same way? For example, how could I put this configuration example from the NLog documentation for ASP.NET Core 2 into

Inject generic interface in .NET Core

左心房为你撑大大i 提交于 2021-01-20 16:12:06
问题 I want to inject this interface to my controllers: public interface IDatabaseService<T> where T : class { T GetItem(int id); IEnumerable<T> GetList(); void Edit(T data); void Add(T data); void Remove(T data); } I want to use generic, because in my WebApi project i have controllers like ProjectController , TaskController etc and i want to use generic interface to each of type (for example, IDatabaseService<Project> , IdatabaseService<Task> etc). Class, that will be injected to controller will

Inject generic interface in .NET Core

心已入冬 提交于 2021-01-20 16:11:38
问题 I want to inject this interface to my controllers: public interface IDatabaseService<T> where T : class { T GetItem(int id); IEnumerable<T> GetList(); void Edit(T data); void Add(T data); void Remove(T data); } I want to use generic, because in my WebApi project i have controllers like ProjectController , TaskController etc and i want to use generic interface to each of type (for example, IDatabaseService<Project> , IdatabaseService<Task> etc). Class, that will be injected to controller will

Running a C# program with command line prompts in Visual Studio Code

自作多情 提交于 2021-01-20 07:35:10
问题 I am running an inherited project written in C# inside Visual Studio Code. In order for this application to run, it needs to take command line input (-t, -h, etc). How do I test this from inside Visual Studio? Currently (I've been learning dotnet, C#, VS, etc as I go) I have a hello world program I can run from vsc's terminal. For a reason I haven't been able to pinpoint, probably how I installed it, dotnet run isn't recognized - I have to feed it an explicit path to dotnet.exe: C:\Program

What is the simplest way to run a single background task from a controller in .NET Core?

喜夏-厌秋 提交于 2021-01-19 06:17:52
问题 I have an ASP.NET Core web app, with WebAPI controllers. All I am trying to do is, in some of the controllers, be able to kick off a process that would run in the background, but the controller should go ahead and return before that process is done. I don't want the consumers of the service to have to wait for this job to finish. I have seen all of the posts about IHostedService and BackgroundService, but none of them seem to be what I want. Also, all these examples show you how to set things

Why Logging doesn't use string interpolation

最后都变了- 提交于 2021-01-18 07:44:07
问题 I have been following Logging in ASP.NET Core Which is working just fine. I have a question about this line _logger.LogWarning(LoggingEvents.GetItemNotFound, "GetById({ID}) NOT FOUND", id); I am wondering why they are not using $ - string interpolation? _logger.LogWarning(LoggingEvents.GetItemNotFound, $"GetById({ID}) NOT FOUND"); Why would the LogWarning extension have a params object[] args paramater? Whats the point when you can just send everything in string message. I assume there is a

IActionResult vs ObjectResult vs JsonResult in ASP.NET Core API

两盒软妹~` 提交于 2021-01-18 04:10:48
问题 What's the best option to use in a Web API that will return both HTTP status codes and JSON results? I've always used IActionResult but it was always a Web App with a Web API. This time it's only Web API . I have the following simple method that's giving me an error that reads: Cannot implicitly convert type Microsoft.AspNetCore.Mvc.OkObjectResult to System.Threading.Tasks.Task Microsoft.AspNetCore.Mvc.IActionResult [HttpGet] public Task<IActionResult> Get() { return Ok(); } 回答1: Return the