Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. .Net Logging

.Net Logging

Scheduled Pinned Locked Moved The Lounge
csharphelptoolstutorialquestion
51 Posts 34 Posters 55 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Bassam Abdul Baki

    For the other side, are you familiar with Microsoft's [Log Parser 2.2](https://technet.microsoft.com/en-us/scriptcenter/dd919274.aspx)?

    Web - BM - RSS - Math - LinkedIn

    K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #3

    No, haven't seen it. I'm just venting on why it's so blasted much work just to write to a log file.

    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

    1 Reply Last reply
    0
    • K Kevin Marois

      So I'm looking at NLog and Log4net. Why in the world does logging need to be so blasted complicated??? Now I'm sure some of you would say "Log4Net or NLog isn't complicated", but at the most basicl level, what's wrong with this:

      public class Logger
      {
      public static string LogFile { get; set; }

      static Logger()
      {
      	if (string.IsNullOrEmpty(LogFile))
      	{
      		var path = System.Reflection.Assembly.GetEntryAssembly().Location;
      		LogFile = string.Format("{0}\\\\MyLogFile.txt", path);
      	}
      }
      
      public static void Info(string message)
      {
      	using (var sr = new StreamWriter(LogFile, true))
      	{
      		sr.WriteLine(message);
      	}
      }
      

      }

      I've never understood why [This Much](https://csharp.today/log4net-tutorial-great-library-for-logging/) is needed just to write to a silly log file. Seems to me that these "tools" are just a solution looking for a problem. IMHO, WAY WAY WAY over-engineered.

      If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #4

      Logging frameworks (etc.) are for developers who are too stupid to figure it out for themselves. If you're smart enough to recognize that the framework is crap, you don't need that framework. :cool:

      K B 2 Replies Last reply
      0
      • P PIEBALDconsult

        Logging frameworks (etc.) are for developers who are too stupid to figure it out for themselves. If you're smart enough to recognize that the framework is crap, you don't need that framework. :cool:

        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #5

        I disagree. When you have code running in production it;s usually more difficult to diagnose what's happening, so logging gives you an advantage.

        If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

        P T 2 Replies Last reply
        0
        • K Kevin Marois

          So I'm looking at NLog and Log4net. Why in the world does logging need to be so blasted complicated??? Now I'm sure some of you would say "Log4Net or NLog isn't complicated", but at the most basicl level, what's wrong with this:

          public class Logger
          {
          public static string LogFile { get; set; }

          static Logger()
          {
          	if (string.IsNullOrEmpty(LogFile))
          	{
          		var path = System.Reflection.Assembly.GetEntryAssembly().Location;
          		LogFile = string.Format("{0}\\\\MyLogFile.txt", path);
          	}
          }
          
          public static void Info(string message)
          {
          	using (var sr = new StreamWriter(LogFile, true))
          	{
          		sr.WriteLine(message);
          	}
          }
          

          }

          I've never understood why [This Much](https://csharp.today/log4net-tutorial-great-library-for-logging/) is needed just to write to a silly log file. Seems to me that these "tools" are just a solution looking for a problem. IMHO, WAY WAY WAY over-engineered.

          If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #6

          For a simple application, what you posted may suffice. For complex, multi threaded services, the logging needs to be thread-safe, needs to be performant (even async), and may need to support multiple log listeners - and the target may be a text file, a database, azure storage, a web API, etc. That said, some of these logging frameworks kept adding features and now are unnecessarily complex, and may have reached a saturation point of over-engineering.

          Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com

          J 1 Reply Last reply
          0
          • K Kevin Marois

            So I'm looking at NLog and Log4net. Why in the world does logging need to be so blasted complicated??? Now I'm sure some of you would say "Log4Net or NLog isn't complicated", but at the most basicl level, what's wrong with this:

            public class Logger
            {
            public static string LogFile { get; set; }

            static Logger()
            {
            	if (string.IsNullOrEmpty(LogFile))
            	{
            		var path = System.Reflection.Assembly.GetEntryAssembly().Location;
            		LogFile = string.Format("{0}\\\\MyLogFile.txt", path);
            	}
            }
            
            public static void Info(string message)
            {
            	using (var sr = new StreamWriter(LogFile, true))
            	{
            		sr.WriteLine(message);
            	}
            }
            

            }

            I've never understood why [This Much](https://csharp.today/log4net-tutorial-great-library-for-logging/) is needed just to write to a silly log file. Seems to me that these "tools" are just a solution looking for a problem. IMHO, WAY WAY WAY over-engineered.

            If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

            I Offline
            I Offline
            Ian Shlasko
            wrote on last edited by
            #7

            X = What features you need from your logging system Y = What features a logging framework provides Usefulness of logging system = 1 / (Y - X)

            Proud to have finally moved to the A-Ark. Which one are you in?
            Author of the Guardians Saga (Sci-Fi/Fantasy novels)

            1 Reply Last reply
            0
            • K Kevin Marois

              I disagree. When you have code running in production it;s usually more difficult to diagnose what's happening, so logging gives you an advantage.

              If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #8

              I never said otherwise.

              1 Reply Last reply
              0
              • K Kevin Marois

                So I'm looking at NLog and Log4net. Why in the world does logging need to be so blasted complicated??? Now I'm sure some of you would say "Log4Net or NLog isn't complicated", but at the most basicl level, what's wrong with this:

                public class Logger
                {
                public static string LogFile { get; set; }

                static Logger()
                {
                	if (string.IsNullOrEmpty(LogFile))
                	{
                		var path = System.Reflection.Assembly.GetEntryAssembly().Location;
                		LogFile = string.Format("{0}\\\\MyLogFile.txt", path);
                	}
                }
                
                public static void Info(string message)
                {
                	using (var sr = new StreamWriter(LogFile, true))
                	{
                		sr.WriteLine(message);
                	}
                }
                

                }

                I've never understood why [This Much](https://csharp.today/log4net-tutorial-great-library-for-logging/) is needed just to write to a silly log file. Seems to me that these "tools" are just a solution looking for a problem. IMHO, WAY WAY WAY over-engineered.

                If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                D Offline
                D Offline
                dandy72
                wrote on last edited by
                #9

                Clearly some stuff is over-engineered. If what you've posted meets your requirements, then by all means--you shouldn't ever feel obligated to use any of the bloated alternatives that exist.

                1 Reply Last reply
                0
                • K Kevin Marois

                  So I'm looking at NLog and Log4net. Why in the world does logging need to be so blasted complicated??? Now I'm sure some of you would say "Log4Net or NLog isn't complicated", but at the most basicl level, what's wrong with this:

                  public class Logger
                  {
                  public static string LogFile { get; set; }

                  static Logger()
                  {
                  	if (string.IsNullOrEmpty(LogFile))
                  	{
                  		var path = System.Reflection.Assembly.GetEntryAssembly().Location;
                  		LogFile = string.Format("{0}\\\\MyLogFile.txt", path);
                  	}
                  }
                  
                  public static void Info(string message)
                  {
                  	using (var sr = new StreamWriter(LogFile, true))
                  	{
                  		sr.WriteLine(message);
                  	}
                  }
                  

                  }

                  I've never understood why [This Much](https://csharp.today/log4net-tutorial-great-library-for-logging/) is needed just to write to a silly log file. Seems to me that these "tools" are just a solution looking for a problem. IMHO, WAY WAY WAY over-engineered.

                  If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #10

                  Kevin Marois wrote:

                  at the most basicl level, what's wrong with this:

                  public class Logger
                  {
                  public static string LogFile { get; set; }

                  static Logger()
                  {
                      if (string.IsNullOrEmpty(LogFile))
                      {
                          var path = System.Reflection.Assembly.GetEntryAssembly().Location;
                          LogFile = string.Format("{0}\\MyLogFile.txt", path);
                      }
                  }
                  

                  Well, it won't work in production for starters! The Executing assembly in production is normally in a folder that "hangs off" "Program Files" or "Program Files (x86)", and folders in that path are normally write protected for antivirus reasons. Use a "publically writable" folder like one below Application.CommonAppDataPath or Environment.SpecialFolder.CommonApplicationData :

                  /// <summary>
                  /// Get the Application Guid
                  /// </summary>
                  public static Guid AppGuid
                  {
                  get
                  {
                  Assembly asm = Assembly.GetEntryAssembly();
                  object[] attr = (asm.GetCustomAttributes(typeof(GuidAttribute), true));
                  return new Guid((attr[0] as GuidAttribute).Value);
                  }
                  }
                  /// <summary>
                  /// Get the current assembly Guid.
                  /// <remarks>
                  /// Note that the Assembly Guid is not necessarily the same as the
                  /// Application Guid - if this code is in a DLL, the Assembly Guid
                  /// will be the Guid for the DLL, not the active EXE file.
                  /// </remarks>
                  /// </summary>
                  public static Guid AssemblyGuid
                  {
                  get
                  {
                  Assembly asm = Assembly.GetExecutingAssembly();
                  object[] attr = (asm.GetCustomAttributes(typeof(GuidAttribute), true));
                  return new Guid((attr[0] as GuidAttribute).Value);
                  }
                  }
                  /// <summary>
                  /// Get all users data folder
                  /// </summary>
                  public static string AllUsersDataFolder
                  {
                  get
                  {
                  Guid appGuid = AppGuid;
                  string folderBase = Environment.GetFolderPath(Environme

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  K 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    Kevin Marois wrote:

                    at the most basicl level, what's wrong with this:

                    public class Logger
                    {
                    public static string LogFile { get; set; }

                    static Logger()
                    {
                        if (string.IsNullOrEmpty(LogFile))
                        {
                            var path = System.Reflection.Assembly.GetEntryAssembly().Location;
                            LogFile = string.Format("{0}\\MyLogFile.txt", path);
                        }
                    }
                    

                    Well, it won't work in production for starters! The Executing assembly in production is normally in a folder that "hangs off" "Program Files" or "Program Files (x86)", and folders in that path are normally write protected for antivirus reasons. Use a "publically writable" folder like one below Application.CommonAppDataPath or Environment.SpecialFolder.CommonApplicationData :

                    /// <summary>
                    /// Get the Application Guid
                    /// </summary>
                    public static Guid AppGuid
                    {
                    get
                    {
                    Assembly asm = Assembly.GetEntryAssembly();
                    object[] attr = (asm.GetCustomAttributes(typeof(GuidAttribute), true));
                    return new Guid((attr[0] as GuidAttribute).Value);
                    }
                    }
                    /// <summary>
                    /// Get the current assembly Guid.
                    /// <remarks>
                    /// Note that the Assembly Guid is not necessarily the same as the
                    /// Application Guid - if this code is in a DLL, the Assembly Guid
                    /// will be the Guid for the DLL, not the active EXE file.
                    /// </remarks>
                    /// </summary>
                    public static Guid AssemblyGuid
                    {
                    get
                    {
                    Assembly asm = Assembly.GetExecutingAssembly();
                    object[] attr = (asm.GetCustomAttributes(typeof(GuidAttribute), true));
                    return new Guid((attr[0] as GuidAttribute).Value);
                    }
                    }
                    /// <summary>
                    /// Get all users data folder
                    /// </summary>
                    public static string AllUsersDataFolder
                    {
                    get
                    {
                    Guid appGuid = AppGuid;
                    string folderBase = Environment.GetFolderPath(Environme

                    K Offline
                    K Offline
                    Kevin Marois
                    wrote on last edited by
                    #11

                    Agreed. I just threw that in there for illustrative purposes

                    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                    H 1 Reply Last reply
                    0
                    • K Kevin Marois

                      So I'm looking at NLog and Log4net. Why in the world does logging need to be so blasted complicated??? Now I'm sure some of you would say "Log4Net or NLog isn't complicated", but at the most basicl level, what's wrong with this:

                      public class Logger
                      {
                      public static string LogFile { get; set; }

                      static Logger()
                      {
                      	if (string.IsNullOrEmpty(LogFile))
                      	{
                      		var path = System.Reflection.Assembly.GetEntryAssembly().Location;
                      		LogFile = string.Format("{0}\\\\MyLogFile.txt", path);
                      	}
                      }
                      
                      public static void Info(string message)
                      {
                      	using (var sr = new StreamWriter(LogFile, true))
                      	{
                      		sr.WriteLine(message);
                      	}
                      }
                      

                      }

                      I've never understood why [This Much](https://csharp.today/log4net-tutorial-great-library-for-logging/) is needed just to write to a silly log file. Seems to me that these "tools" are just a solution looking for a problem. IMHO, WAY WAY WAY over-engineered.

                      If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #12

                      Above was mentioned thread safe, another gotya is running multiple instances of the same prog. BTW:

                      Kevin Marois wrote:

                      've never understood why This Much is needed just to write to a silly log file

                      If the log file is silly, why log anything.

                      Sin tack ear lol Pressing the any key may be continuate

                      1 Reply Last reply
                      0
                      • K Kevin Marois

                        So I'm looking at NLog and Log4net. Why in the world does logging need to be so blasted complicated??? Now I'm sure some of you would say "Log4Net or NLog isn't complicated", but at the most basicl level, what's wrong with this:

                        public class Logger
                        {
                        public static string LogFile { get; set; }

                        static Logger()
                        {
                        	if (string.IsNullOrEmpty(LogFile))
                        	{
                        		var path = System.Reflection.Assembly.GetEntryAssembly().Location;
                        		LogFile = string.Format("{0}\\\\MyLogFile.txt", path);
                        	}
                        }
                        
                        public static void Info(string message)
                        {
                        	using (var sr = new StreamWriter(LogFile, true))
                        	{
                        		sr.WriteLine(message);
                        	}
                        }
                        

                        }

                        I've never understood why [This Much](https://csharp.today/log4net-tutorial-great-library-for-logging/) is needed just to write to a silly log file. Seems to me that these "tools" are just a solution looking for a problem. IMHO, WAY WAY WAY over-engineered.

                        If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #13

                        Wrap it all in one static call. If logging is "intense" enough, feed a concurrent queue with a background worker to serialize it.

                        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                        1 Reply Last reply
                        0
                        • K Kevin Marois

                          So I'm looking at NLog and Log4net. Why in the world does logging need to be so blasted complicated??? Now I'm sure some of you would say "Log4Net or NLog isn't complicated", but at the most basicl level, what's wrong with this:

                          public class Logger
                          {
                          public static string LogFile { get; set; }

                          static Logger()
                          {
                          	if (string.IsNullOrEmpty(LogFile))
                          	{
                          		var path = System.Reflection.Assembly.GetEntryAssembly().Location;
                          		LogFile = string.Format("{0}\\\\MyLogFile.txt", path);
                          	}
                          }
                          
                          public static void Info(string message)
                          {
                          	using (var sr = new StreamWriter(LogFile, true))
                          	{
                          		sr.WriteLine(message);
                          	}
                          }
                          

                          }

                          I've never understood why [This Much](https://csharp.today/log4net-tutorial-great-library-for-logging/) is needed just to write to a silly log file. Seems to me that these "tools" are just a solution looking for a problem. IMHO, WAY WAY WAY over-engineered.

                          If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                          Richard DeemingR Offline
                          Richard DeemingR Offline
                          Richard Deeming
                          wrote on last edited by
                          #14

                          Have you seen Serilog[^]? It looks fairly simple to set up and use.


                          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                          1 Reply Last reply
                          0
                          • N Nish Nishant

                            For a simple application, what you posted may suffice. For complex, multi threaded services, the logging needs to be thread-safe, needs to be performant (even async), and may need to support multiple log listeners - and the target may be a text file, a database, azure storage, a web API, etc. That said, some of these logging frameworks kept adding features and now are unnecessarily complex, and may have reached a saturation point of over-engineering.

                            Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com

                            J Offline
                            J Offline
                            Jeremy Falcon
                            wrote on last edited by
                            #15

                            Nish Nishant wrote:

                            That said, some of these logging frameworks kept adding features and now are unnecessarily complex, and may have reached a saturation point of over-engineering.

                            Adobe is doing the same thing with Photoshop now. I hope it doesn't get worse, that's been one of my favorite apps for so many years. If it goes to crap it'll be a sad, sad day for computerland. :((

                            Jeremy Falcon

                            N P 2 Replies Last reply
                            0
                            • J Jeremy Falcon

                              Nish Nishant wrote:

                              That said, some of these logging frameworks kept adding features and now are unnecessarily complex, and may have reached a saturation point of over-engineering.

                              Adobe is doing the same thing with Photoshop now. I hope it doesn't get worse, that's been one of my favorite apps for so many years. If it goes to crap it'll be a sad, sad day for computerland. :((

                              Jeremy Falcon

                              N Offline
                              N Offline
                              Nish Nishant
                              wrote on last edited by
                              #16

                              I don't have it yet but the personal use subscription is quite affordable. 10 bucks a month gives you Photoshop and a couple other tools I think. You never really own it though - just a lease.

                              Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com

                              J 1 Reply Last reply
                              0
                              • K Kevin Marois

                                So I'm looking at NLog and Log4net. Why in the world does logging need to be so blasted complicated??? Now I'm sure some of you would say "Log4Net or NLog isn't complicated", but at the most basicl level, what's wrong with this:

                                public class Logger
                                {
                                public static string LogFile { get; set; }

                                static Logger()
                                {
                                	if (string.IsNullOrEmpty(LogFile))
                                	{
                                		var path = System.Reflection.Assembly.GetEntryAssembly().Location;
                                		LogFile = string.Format("{0}\\\\MyLogFile.txt", path);
                                	}
                                }
                                
                                public static void Info(string message)
                                {
                                	using (var sr = new StreamWriter(LogFile, true))
                                	{
                                		sr.WriteLine(message);
                                	}
                                }
                                

                                }

                                I've never understood why [This Much](https://csharp.today/log4net-tutorial-great-library-for-logging/) is needed just to write to a silly log file. Seems to me that these "tools" are just a solution looking for a problem. IMHO, WAY WAY WAY over-engineered.

                                If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                                S Offline
                                S Offline
                                Slacker007
                                wrote on last edited by
                                #17

                                pencil and paper. when an error happens, write it down. Simples. :-D

                                N 1 Reply Last reply
                                0
                                • N Nish Nishant

                                  I don't have it yet but the personal use subscription is quite affordable. 10 bucks a month gives you Photoshop and a couple other tools I think. You never really own it though - just a lease.

                                  Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com

                                  J Offline
                                  J Offline
                                  Jeremy Falcon
                                  wrote on last edited by
                                  #18

                                  Yeah totally, and they allow you to use it on more than one computer, so it's not too shabby. But when you start using the new version (CC 2017) it just starts to seem like the new crap is just too much and is distracting. And I've always used Photoshop as an example of a simple, clean yet powerful UI design. Not so much now.

                                  Jeremy Falcon

                                  1 Reply Last reply
                                  0
                                  • K Kevin Marois

                                    I disagree. When you have code running in production it;s usually more difficult to diagnose what's happening, so logging gives you an advantage.

                                    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                                    T Offline
                                    T Offline
                                    TheGreatAndPowerfulOz
                                    wrote on last edited by
                                    #19

                                    Me thinks you misunderstood. By "the framework" he's referencing "the Logging framework", not logging in general.

                                    #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                                    1 Reply Last reply
                                    0
                                    • S Slacker007

                                      pencil and paper. when an error happens, write it down. Simples. :-D

                                      N Offline
                                      N Offline
                                      Nish Nishant
                                      wrote on last edited by
                                      #20

                                      The old methods work best. I have heard that's how Google handles its internal search service logging. They have a team of 100 people with writing pads and pencils. :-D

                                      Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com

                                      S 1 Reply Last reply
                                      0
                                      • K Kevin Marois

                                        So I'm looking at NLog and Log4net. Why in the world does logging need to be so blasted complicated??? Now I'm sure some of you would say "Log4Net or NLog isn't complicated", but at the most basicl level, what's wrong with this:

                                        public class Logger
                                        {
                                        public static string LogFile { get; set; }

                                        static Logger()
                                        {
                                        	if (string.IsNullOrEmpty(LogFile))
                                        	{
                                        		var path = System.Reflection.Assembly.GetEntryAssembly().Location;
                                        		LogFile = string.Format("{0}\\\\MyLogFile.txt", path);
                                        	}
                                        }
                                        
                                        public static void Info(string message)
                                        {
                                        	using (var sr = new StreamWriter(LogFile, true))
                                        	{
                                        		sr.WriteLine(message);
                                        	}
                                        }
                                        

                                        }

                                        I've never understood why [This Much](https://csharp.today/log4net-tutorial-great-library-for-logging/) is needed just to write to a silly log file. Seems to me that these "tools" are just a solution looking for a problem. IMHO, WAY WAY WAY over-engineered.

                                        If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                                        Sander RosselS Offline
                                        Sander RosselS Offline
                                        Sander Rossel
                                        wrote on last edited by
                                        #21

                                        We currently use log4net... To log to a file. Well, 10 files actually. Of 10 MB max. After which it overwrites the first again. That shit is totally unreadable and for some reason we have to log EVERYTHING. Yes, I DO believe some function was entered AND exited unless an error occurred, WHY THE HELL DO WE NEED TO LOG THAT!? The worst part, our source code is littered with debug log statements and on all environments we have the minimum log level set to info, so the debug logs never even show. Some people say "it's easy for debugging", but since when is a log file easier for debugging than a friggin' debugger!? Then again, I recently figured out a bug in three minutes using nothing but an error message and a stack trace after a coworker angrily gave me the (my) code because "I didn't add log statements and now he had to spent 30 minutes figuring out what went wrong!" It was a NullReference and by just looking at the code you could tell what parameters could be null, well at least I could :~ Yes, logging is good, but only if they are exception logs (with stack trace!!!) or logging that is required for the business. And rarely for debugging purposes, for example when multi-threading or handling input events (but in your console while debugging, not in a log file on production). Funny enough I've had this discussion with multiple people who all disagree with me (and despite all that logging which I don't use I usually find bugs faster) :confused:

                                        Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly

                                        M 1 Reply Last reply
                                        0
                                        • K Kevin Marois

                                          So I'm looking at NLog and Log4net. Why in the world does logging need to be so blasted complicated??? Now I'm sure some of you would say "Log4Net or NLog isn't complicated", but at the most basicl level, what's wrong with this:

                                          public class Logger
                                          {
                                          public static string LogFile { get; set; }

                                          static Logger()
                                          {
                                          	if (string.IsNullOrEmpty(LogFile))
                                          	{
                                          		var path = System.Reflection.Assembly.GetEntryAssembly().Location;
                                          		LogFile = string.Format("{0}\\\\MyLogFile.txt", path);
                                          	}
                                          }
                                          
                                          public static void Info(string message)
                                          {
                                          	using (var sr = new StreamWriter(LogFile, true))
                                          	{
                                          		sr.WriteLine(message);
                                          	}
                                          }
                                          

                                          }

                                          I've never understood why [This Much](https://csharp.today/log4net-tutorial-great-library-for-logging/) is needed just to write to a silly log file. Seems to me that these "tools" are just a solution looking for a problem. IMHO, WAY WAY WAY over-engineered.

                                          If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                                          R Offline
                                          R Offline
                                          Rob Philpott
                                          wrote on last edited by
                                          #22

                                          Well, I agree that config is a bit of pain to sort out. But like with WCF you do it once then forget about it.

                                          Kevin Marois wrote:

                                          what's wrong with this:

                                          Quite a lot. Opening and closing a file every time you want to write a line isn't going to perform well. It *may* not be threadsafe, there's no mention of when the line was written or from which thread it happened. It always writes to a file, good for services but rubbish for a console app and if you've done it right your app will be both (enterprise solutions). It doesn't standardise on the format of each log line (important if you use a decent viewer). There's no concept of level - how do you distinguish a bit of helpful text from a critical error? How do you stop your file growing to GBs? Each to their own...

                                          Regards, Rob Philpott.

                                          T 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups