ff14-advanced-market-search / AzerothAuctionAssassin

Apache License 2.0
9 stars 11 forks source link

Need Crash Logs or Reporting #109

Open cohenaj194 opened 5 months ago

cohenaj194 commented 5 months ago

We need something that tells us what happens when the app dies. Right now you either have to do a screen recording and capture the error. The current issue with 1.1.0 is that it doesnt even open.

We need real error messages or a crashlog that can tell me the specific error and why its crashing.

cohenaj194 commented 9 hours ago

@coderabbitai how can we do this and maybe record logs or stdout to a text file that people can review and send when theres crashes in the exe

coderabbitai[bot] commented 9 hours ago

[!TIP] For best results, initiate chat on the files or code changes.

@cohenaj194, to record logs and capture stdout or errors to a text file when the application crashes, you can implement a logging mechanism within your application. Here are some steps you can consider:

  1. Implement Logging Framework: Integrate a logging library or use the built-in logging features of your programming language to log important events, errors, and exceptions to a file.

    • For C# Applications:

      • Use a logging library like NLog or log4net.
      • Configure the logger to write logs to a file, including error details and stack traces.
      • Example using NLog:
      using NLog;
      
      class Program
      {
         private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
      
         static void Main(string[] args)
         {
             AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
             {
                 Logger.Fatal(e.ExceptionObject as Exception, "Unhandled exception occurred");
             };
      
             try
             {
                 // Your application code here
             }
             catch (Exception ex)
             {
                 Logger.Error(ex, "An error occurred");
                 throw;
             }
         }
      }
      • Configure NLog.config to specify the log file location and format.
    • For Python Applications:

      • Use the built-in logging module.
      • Example:
      import logging
      import sys
      
      def handle_exception(exc_type, exc_value, exc_traceback):
         if issubclass(exc_type, KeyboardInterrupt):
             sys.__excepthook__(exc_type, exc_value, exc_traceback)
             return
         logging.critical("Unhandled exception", exc_info=(exc_type, exc_value, exc_traceback))
      
      sys.excepthook = handle_exception
      
      logging.basicConfig(filename='app.log', level=logging.DEBUG)
      
      try:
         # Your application code here
      except Exception as e:
         logging.exception("An error occurred")
         raise
  2. Catch Unhandled Exceptions: Set up global exception handlers to catch any unhandled exceptions and log them.

    • In C#:

      • Subscribe to AppDomain.CurrentDomain.UnhandledException for non-UI threads.
      • For WPF applications, handle Application.DispatcherUnhandledException.
      • For WinForms applications, handle Application.ThreadException.
    • In Python:

      • Override sys.excepthook as shown above.
  3. Redirect Standard Output and Error: Capture all console output by redirecting stdout and stderr to a file.

    • In C#:

      using System.IO;
      
      var logFile = "output.log";
      var fileStream = new FileStream(logFile, FileMode.Create);
      var streamWriter = new StreamWriter(fileStream) { AutoFlush = true };
      Console.SetOut(streamWriter);
      Console.SetError(streamWriter);
    • In Python:

      import sys
      
      sys.stdout = open('stdout.log', 'w')
      sys.stderr = open('stderr.log', 'w')
  4. Store Logs in Accessible Location: Ensure that log files are saved in a location that's easy for users to find, such as the application's directory or a dedicated logs folder.

  5. Inform Users: Provide instructions to users on how to locate and send the log files when reporting an issue.

  6. Crash Reporting Tools (Optional): Integrate third-party crash reporting tools that automatically collect and send crash reports.

  7. Testing: After implementing logging, test the application by inducing errors to ensure that logs are recorded as expected.

Implementing these steps will help you gather detailed information when the application fails to start or crashes unexpectedly. This way, users can provide you with the log files, allowing you to diagnose and fix issues more effectively.

Let me know if you need further assistance or code examples for a specific part of your application.