public bool TryLogError(LogSourceInfo logSourceInfo, string message, Exception exception, IEnumerable <object> dataNamesAndValues) { try { string errorMessage = DefaultFormat.ErrorMessage.Construct(message, exception, _formatOptions.UseNewLinesInErrorMessages); StringBuilder logLine = DefaultFormat.LogLine.Construct( DefaultFormat.LogLevelMoniker_Error, logSourceInfo.LogSourceNamePart1, logSourceInfo.LogSourceNamePart2, logSourceInfo.CallLineNumber, logSourceInfo.CallMemberName, logSourceInfo.CallFileName, logSourceInfo.AssemblyName, errorMessage, dataNamesAndValues, _formatOptions.UseUtcTimestamps, _formatOptions.UseNewLinesInDataNamesAndValues); return(TryWriteToFile(logLine.ToString())); } catch { return(false); } }
internal static void Debug(LogSourceInfo logSourceInfo, string message, params object[] dataNamesAndValues) { if (s_config_IsDebugLoggingEnabled) { Action <string, string, int, string, string, string, string, IEnumerable <object> > logEventHandler = s_config_EventHandlers_Debug; if (logEventHandler != null) { // If AutomaticAssemblyName is enabled AND AssemblyName is not already specified, look into including the assembly name now. if (s_config_AutomaticAssemblyName_ForDebug_Include && logSourceInfo.AssemblyName == null) { // If AutomaticAssemblyName inclusion period has passed, add the assembly name (xxx_PeriodMillisecs < 1 indicates "always include"). // There is a benign race on R/W of xxx_LastTimestamp: We may log all the assembly names a few extra times or get the period off by a few millisecs. if (s_config_AutomaticAssemblyName_ForDebug_PeriodMillisecs <= 0 || GetEnvironmentTicksSince(s_AutomaticAssemblyName_ForDebug_LastTimestamp, out s_AutomaticAssemblyName_ForDebug_LastTimestamp) >= s_config_AutomaticAssemblyName_ForDebug_PeriodMillisecs) { logSourceInfo = logSourceInfo.WithAssemblyName(); } } logEventHandler(logSourceInfo.LogSourceNamePart1, logSourceInfo.LogSourceNamePart2, logSourceInfo.CallLineNumber, logSourceInfo.CallMemberName, logSourceInfo.CallFileName, logSourceInfo.AssemblyName, message, GetDataNamesAndValuesEnum(dataNamesAndValues)); } } }
/// <summary> /// This method logs and rethrows the exception. It is typed to return the exception, to enable writing concise code like: /// <code> /// try /// { /// // ... /// } /// catch (Exception ex) /// { /// throw Log.ErrorRethrow("...", ex); /// } /// </code> /// The throwing actually happens inside of the <c>ErrorRethrow(..)<.c> method. However, this syntaxt allows the compiler to know that /// an exception will occur at that line. This prevents incorrect code analysis warnings/end errors such as 'missing return value', /// 'missing initialization' and similar. /// </summary> /// <returns>Either <c>null</c> if the specified <c>exception</c> is <c>null</c>, or nothing at all, /// because the specified <c>exception</c> is rethrown.</returns> internal static Exception ErrorRethrow(LogSourceInfo logSourceInfo, string message, Exception exception, params object[] dataNamesAndValues) { Error(logSourceInfo, message, exception, dataNamesAndValues); if (exception != null) { ExceptionDispatchInfo.Capture(exception).Throw(); } return(exception); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); TaskScheduler.UnobservedTaskException += (sender, args) => HandleException(args.Exception); container = new CompositionContainer(new AssemblyCatalog(typeof(App).Assembly)); var activationArguments = AppDomain.CurrentDomain.SetupInformation.ActivationArguments; var activationData = activationArguments != null ? activationArguments.ActivationData : null; var filePath = (activationData ?? e.Args) .Select(x => x.Replace("file:///", string.Empty)) .FirstOrDefault(); this.ShutdownMode = ShutdownMode.OnExplicitShutdown; if (string.IsNullOrEmpty(filePath)) { var view = new SelectSourceView(); container.SatisfyImportsOnce(view.ViewModel); if (view.ShowDialog() == true) { SourceInfo = view.ViewModel.Source; } } else { var factory = new FileLogSourceFactory(); SourceInfo = factory.Create(SelectFormat, filePath); } if (SourceInfo == null) { this.Shutdown(); return; } this.ShutdownMode = ShutdownMode.OnLastWindowClose; this.MainWindow = new ShellView(); this.MainWindow.Closed += (sender, args) => SourceInfo.Source.Dispose(); this.MainWindow.Show(); }
public bool TryLogDebug(LogSourceInfo logSourceInfo, string message, IEnumerable <object> dataNamesAndValues) { try { SimpleConsoleSink.Debug(logSourceInfo.LogSourceNamePart1, logSourceInfo.LogSourceNamePart2, logSourceInfo.CallLineNumber, logSourceInfo.CallMemberName, logSourceInfo.CallFileName, logSourceInfo.AssemblyName, message, dataNamesAndValues); return(true); } catch { return(false); } }
/// <summary> /// This method logs and rethrows the exception. It is typed to return the exception, to enable writing concise code like: /// <code> /// try /// { /// // ... /// } /// catch (Exception ex) /// { /// throw Log.ErrorRethrow("...", ex); /// } /// </code> /// The throwing actually happens inside of the <c>ErrorRethrow(..)<.c> method. However, this syntaxt allows the compiler to know that /// an exception will occur at that line. This prevents incorrect code analysis warnings/end errors such as 'missing return value', /// 'missing initialization' and similar. /// </summary> /// <returns>Either <c>null</c> if the specified <c>exception</c> is <c>null</c>, or nothing at all, /// because the specified <c>exception</c> is rethrown.</returns> internal static Exception ErrorRethrow(LogSourceInfo logSourceInfo, Exception exception, params object[] dataNamesAndValues) { return(ErrorRethrow(logSourceInfo, message: null, exception, dataNamesAndValues)); }
internal static void Error(LogSourceInfo logSourceInfo, Exception exception, params object[] dataNamesAndValues) { Error(logSourceInfo, message: null, exception, dataNamesAndValues); }
internal static void Error(LogSourceInfo logSourceInfo, string message, params object[] dataNamesAndValues) { Error(logSourceInfo, message, exception: null, dataNamesAndValues); }
internal static LogSourceInfo WithCallInfo(LogSourceInfo logSourceInfo, [CallerLineNumber] int callLineNumber = 0, [CallerMemberName] string callMemberName = null) { return(logSourceInfo.WithCallInfo(callLineNumber, callMemberName)); }
public bool TryLogDebug(LogSourceInfo logSourceInfo, string message, IEnumerable <object> dataNamesAndValues) { return(_downstreamLogSink.TryLogDebug(logSourceInfo.WithinLogSourcesGroup(_logSourcesGroupMoniker), message, dataNamesAndValues)); }
public bool TryLogDebug(LogSourceInfo logSourceInfo, string message, IEnumerable <object> dataNamesAndValues) { InvokeForAllLogSinks((ls) => ls.TryLogDebug(logSourceInfo, message, dataNamesAndValues), out bool allSucceeded); return(allSucceeded); }