question

MarkusFreitag-0088 avatar image
0 Votes"
MarkusFreitag-0088 asked TimonYang-MSFT commented

Logging in parallel without loss of time.

Hello,

Which class, assembly is suitable for the following topic?

Logging
20210705.log for each day

13:13:51.474;[INFO];## Init SCADA system
13:13:56.470;(5);[Tester][MACHINE IN]: <ROOT><PERMIT_REQ panel="333C_123" segment="1;1" /></ROOT>

If the LogFile is > 10MByte, a new LogFile is created automatically..
If the log file is older than 21 days, delete it automatically.
Everything must be done in parallel without any loss of time or blocking the main application.


I find Log4net difficult to initialise, Google finds a lot, but no concrete example.


 Log.Info(string input);
 Log.Debug(string input);
 Log.Warning(string input);
 Log.Error(string input);

There must be logging for all classes.

I would like to be able to enter the level in a configuration file.
So that I can expand it in the event of an error, if it is running, level info is sufficient.

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

TimonYang-MSFT avatar image
1 Vote"
TimonYang-MSFT answered TimonYang-MSFT commented

This is what should be done using asynchronous.

A simple example, the two methods are executed at the same time without affecting each other.

         static async Task Main(string[] args)
         {
             var task1 =  M1();
             var task2 =  M2();
             await Task.WhenAll(task1, task2);
             Console.WriteLine("Press any key to continue......");
             Console.ReadLine();
         }
    
         public static async Task M1()
         {
             await Task.Factory.StartNew(() =>
             {
                 for (int i = 0; i < 10; i++)
                 {
                     Console.WriteLine("M1 " + i);
                 }
             });
         }
         public static async Task M2()
         {
             await Task.Factory.StartNew(() =>
             {
                 for (int i = 0; i < 10; i++)
                 {
                     Console.WriteLine("M2 " + i);
                 }
             });
         }

As for detecting the size and time of the log file, the FileInfo class can do that:

             FileInfo fileInfo = new FileInfo(@"filePath");
             Console.WriteLine(fileInfo.Length);
             Console.WriteLine(fileInfo.LastWriteTime);
             Console.WriteLine(fileInfo.CreationTime);

I find Log4net difficult to initialise

This question can be raised on Log4Net's GitHub, or you can choose other logging providers:

Third-party logging providers


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.



This question can be raised on Log4Net's GitHub, or you can choose other logging providers:

Which logger do you prefer?

0 Votes 0 ·

I haven't used most of these logging providers, so I can't give you an exact answer.
There should be articles on the Internet that introduce some of them. You can search for them, confirm their specificity, and use them according to your needs.

1 Vote 1 ·