Log Assembly for C#

Markus Freitag 3,786 Reputation points
2020-07-09T09:41:58.343+00:00

Hello,
I need a tool that creates log files for me without blocking the application should be done in parallel.

Furthermore I need to be able to store the log file in this format. <NameOfApplication><YYYY-MM-dd>.log

If the size exceeds 50MByte a new file should be written. After 15 days, they should be deleted automatically.

Are there FreeTools for these requirements? Does anyone have a good sample code for C#, WPF, VS2017? Thanks in advance.
Regards Markus

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,783 questions
0 comments No comments
{count} votes

Accepted answer
  1. Peter Fleischer (former MVP) 19,326 Reputation points
    2020-07-13T09:00:06.68+00:00

    Hi, try following Logger. Unfortunately, it is impossible for me to insert code into this buggy forum UI.

    11865-x.png


6 additional answers

Sort by: Most helpful
  1. Markus Freitag 3,786 Reputation points
    2020-07-11T07:52:44.013+00:00
     public class MainProgram
        {
            public static void Main(string[] args)
            {
                BasicLogger.Run();
    

    .....

     public class BasicLogger
        {
            public static void Run()
            {
                var logger = new LoggerConfiguration()
                    .WriteTo.ColoredConsole()
                    .WriteTo.RollingFile(@"c:\temp\Log-{Date}.txt")
                    .CreateLogger();
                var appointment =
                    new { Id = 1, Subject = "Meeting of database migration", Timestamp = new DateTime(2020, 7, 11) };
    
                logger.Information($"An appointment is booked successfully: {appointment.Id}");
    
                logger.Error($"Failed #TEST# to book an appointment: {appointment.Timestamp}");
            }
    

    I've looked at it, it doesn't look bad.
    how can i define the logger as global, that I can write from main

    Do you have an example?


  2. Markus Freitag 3,786 Reputation points
    2020-07-13T09:41:27.333+00:00

    Unfortunately, it is impossible for me to insert code into this buggy forum UI.

    Yes the old one was better.
    Can you upload it please?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.