static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Exceptions handler var currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += (sender, eventArgs) => { UnhandledExceptionLogger.Log(UVGlue.logFile, (Exception)eventArgs.ExceptionObject, false); }; Application.ThreadException += (sender, eventArgs) => { UnhandledExceptionLogger.Log(UVGlue.logFile, eventArgs.Exception, false); }; Process instance = Misc.GetRunningInstance(); if (null != instance) { WinAPI.ShowWindowAsync(instance.MainWindowHandle, WinAPI.SW_SHOW); WinAPI.SetForegroundWindow(instance.MainWindowHandle); } else { UI.FormStarting fs = new UI.FormStarting(); Application.Run(fs); if (fs.DialogResult == DialogResult.OK) { UVGlue._formMain = new UI.FormMain(); Application.Run(UVGlue._formMain); } } }
static void Main(string[] args) { //Default behavior of this logger is to create subdirectory (relative to exe location) and log to file with name forrmatted with userName text formatted with application version - ProcessId - ThreadName (if any) and current date var tl = new LoggerToFileDefaultEasy(); tl.WriteLine("DefaultLog"); //This method gives ability to change log file name tl.SetFileName("CustomFile.txt"); //You can also use the same instance with same formatting etc. to log to some another file tl.WriteToFile("Text to log to custom file", Path.Combine(Directory.GetCurrentDirectory(), "logInTheSameDir.txt")); //It accepts Exceptions too tl.WriteLine(new ArgumentException("In order to log exceptions directly to text file")); //UnhandledExceptionLogger sample //Subscribing at entry point of an application (or if application uses more than one Application domain like windows service then use this code at entry points of every app domain) AppDomain.CurrentDomain.UnhandledException += (sender, e) => UnhandledExceptionLogger.UnhandledExceptionHandler(e, false, exitCodeAfter: 404); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //Subscribe to handle exceptions which are thrown from other threads Application.ThreadException += (sender, e) => UnhandledExceptionLogger.UnhandledExceptionHandler(e, true, exitCodeAfter: 405); //TODO:Add samples for all loggers }
public ActionResult LogPerformance(bool useCDN, int elapse) { try { _CDNPerformanceLogger.TraceEvent(TraceEventType.Verbose, 0, "useCDN\t{0}\telapse\t{1}", useCDN, elapse); _CDNPerformanceLogger.Flush(); } catch (Exception e) { UnhandledExceptionLogger.Write(e); } return(new EmptyResult()); }
protected void Application_Start(object sender, EventArgs e) { TaskScheduler.UnobservedTaskException += (_, ex) => UnhandledExceptionLogger.LogException(ex.Exception, string.Format("Unobserved exception in async task: {0}", ex.Exception.Message)); ConfigureWebApi(GlobalConfiguration.Configuration); MapApiRoutes(GlobalConfiguration.Configuration); RouteMapper.MapNuGetClientRedirectRoutes(GlobalConfiguration.Configuration, RouteMapper.PathPrefix); RouteMapper.MapApiRoutes(GlobalConfiguration.Configuration); RouteMapper.MapSymbolSourceRoutes(GlobalConfiguration.Configuration); RouteMapper.MapDataServiceRoutes(RouteTable.Routes); }
/// Program entry point static void Main(string[] args) { // Add all /var/lang/bin/shared/*/* directories to the search path foreach (var di in new DirectoryInfo("/var/lang/bin/shared").EnumerateDirectories().SelectMany(di => di.EnumerateDirectories().Select(di2 => di2))) { assemblyDirs.Add(di.FullName); } AssemblyLoadContext.Default.Resolving += OnAssemblyResolving; try { var shouldWaitForDebugger = GetShouldWaitForDebuggerFlag(args, out var positionalArgs); var handler = GetFunctionHandler(positionalArgs); var body = GetEventBody(positionalArgs); if (shouldWaitForDebugger) { Console.Error.WriteLine("Waiting for the debugger to attach..."); if (!DebuggerExtensions.TryWaitForAttaching( _debuggerStatusQueryInterval, _debuggerStatusQueryTimeout)) { Console.Error.WriteLine("Timeout. Proceeding without debugger."); } } var lambdaRuntime = new MockRuntime(handler, body); LambdaBootstrap lambdaBootstrap = new LambdaBootstrap(lambdaRuntime, InternalLogger.NO_OP_LOGGER); UnhandledExceptionLogger.Register(); lambdaBootstrap.Initialize(); lambdaBootstrap.Invoke(); } // Catch all unhandled exceptions from runtime, to prevent user from hanging on them while debugging catch (Exception ex) { Console.Error.WriteLine($"\nUnhandled exception occured in runner:\n{ex}"); } }
protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext) { UnhandledExceptionLogger.LogException(exceptionContext.Error); base.OnIncomingError(exceptionContext, invokerContext); }
public LogCastExceptionLogger(params Type[] excludeExceptions) { _logger = new UnhandledExceptionLogger(excludeExceptions); }
/// Program entry point static void Main(string[] args) { // Add all /var/lang/bin/shared/*/* directories to the search path foreach (var di in new DirectoryInfo("/var/lang/bin/shared").EnumerateDirectories().SelectMany(di => di.EnumerateDirectories().Select(di2 => di2))) { assemblyDirs.Add(di.FullName); } AssemblyLoadContext.Default.Resolving += OnAssemblyResolving; //Console.CancelKeyPress += delegate { // // call methods to clean up //}; Process mockServer = null; try { var shouldWaitForDebugger = GetShouldWaitForDebuggerFlag(args, out var positionalArgs); var handler = GetFunctionHandler(positionalArgs); var body = GetEventBody(positionalArgs); var lambdaRuntime = new MockRuntime(handler, body); mockServer = new Process(); mockServer.StartInfo.FileName = "/var/runtime/mockserver"; mockServer.StartInfo.CreateNoWindow = true; mockServer.StartInfo.RedirectStandardInput = true; mockServer.StartInfo.Environment["DOCKER_LAMBDA_NO_BOOTSTRAP"] = "1"; mockServer.StartInfo.Environment["DOCKER_LAMBDA_USE_STDIN"] = "1"; mockServer.Start(); mockServer.StandardInput.Write(body); mockServer.StandardInput.Close(); if (shouldWaitForDebugger) { Console.Error.WriteLine("Waiting for the debugger to attach..."); if (!DebuggerExtensions.TryWaitForAttaching( _debuggerStatusQueryInterval, _debuggerStatusQueryTimeout)) { Console.Error.WriteLine("Timeout. Proceeding without debugger."); } } var lambdaBootstrap = new LambdaBootstrap(lambdaRuntime, InternalLogger.NO_OP_LOGGER); UnhandledExceptionLogger.Register(); lambdaBootstrap.Initialize(); lambdaBootstrap.Invoke(); } // Catch all unhandled exceptions from runtime, to prevent user from hanging on them while debugging catch (Exception ex) { Console.Error.WriteLine($"\nUnhandled exception occured in runner:\n{ex}"); } finally { if (mockServer != null) { mockServer.Dispose(); } } }
public static void saveImage(CogRecordDisplay image, int index, string result) { string imageBaseDir = AppDomain.CurrentDomain.BaseDirectory + "Image"; if (!Directory.Exists(imageBaseDir)) { Directory.CreateDirectory(imageBaseDir); } var imageDir_today = imageBaseDir + "\\" + DateTime.Now.ToString("MM-dd"); if (!Directory.Exists(imageDir_today)) { Directory.CreateDirectory(imageDir_today); } var imagePath = imageDir_today + "\\" + index + "_" + DateTime.Now.ToString("HHmmss") + ".jpg"; if (result == resultNG) { lock (mu_recentNGImagePath) { recentNGIMagePath = imagePath; } } if (ShouldImageBeSavedBasedOnResult(result)) { try { using (CogImageFileTool fileTool = new CogImageFileTool()) { Image img; lock (mu_SaveAsScreenShot) { img = image.CreateContentBitmap(saveAsScreenShot ? CogDisplayContentBitmapConstants.Display : CogDisplayContentBitmapConstants.Image); } Bitmap bmp = new Bitmap(img); CogImage24PlanarColor cogImage = new CogImage24PlanarColor(bmp); fileTool.InputImage = cogImage; lock (mu_recentNGImagePath) { fileTool.Operator.Open(imagePath, CogImageFileModeConstants.Write); } fileTool.Run(); } } catch (Exception e) { UnhandledExceptionLogger.Log(logFile, e, false); } } //删除过期文件夹 removeOutdatedDirs(imageBaseDir); }