So, we have a registration system in which we use Log.Info and write it to ILogger .
Now we have several workers working in the background, and we want them to write them in their journals. So everything is bundled for Desktop. Everything that is registered during this task should be redirected to its own registrar.
Where we are thinking about creating the Log.SetLoggerForCurrentThread method, we implement it using ThreadLocal. The executing code will look something like this:
public class Worker { ILogger _Logger; public void ExecuteTask() { Log.Info( "This goes to the 'Global' logger" ); using ( Log.SetLoggerForCurrentThread(_Logger) ) { Log.Info( "This goes to local logger" ); DoWork(); } } private async void DoWork() { Log.Info( "Starting..." );
Questions
- When we use the wait, the thread can theoretically handle the work of another worker, thereby mixing local registrars.
- What is the best way to do something like this? What storage method can I use?
- How does
CultureInfo handle this?
Background Information
Most of these Workers will work on an Azure WorkerRole instance, but now and in addition, they will also be launched (once) from the console application.
multithreading c # async-await
Dirk boer
source share