diff --git a/src/DotNetPad/DotNetPad.Applications/Controllers/FileController.cs b/src/DotNetPad/DotNetPad.Applications/Controllers/FileController.cs index a331aa1..408061a 100644 --- a/src/DotNetPad/DotNetPad.Applications/Controllers/FileController.cs +++ b/src/DotNetPad/DotNetPad.Applications/Controllers/FileController.cs @@ -208,7 +208,7 @@ private void CloseAll() string fileExtension = Path.GetExtension(fileName); if (!supportedFileExtensions.Contains(fileExtension)) { - Trace.TraceError(string.Format(CultureInfo.InvariantCulture, "The extension of the file '{0}' is not supported.", fileName)); + Log.Default.Error("The extension of the file '{0}' is not supported.", fileName); messageService.ShowError(shellService.ShellView, Resources.OpenFileUnsupportedExtension, fileName); return null; } @@ -222,7 +222,7 @@ private void CloseAll() private static DocumentContent LoadDocumentContent(DocumentFile documentFile) { - Trace.WriteLine(">> Load document content: " + documentFile.FileName); + Log.Default.Trace("Load document content: {0}", documentFile.FileName); using var stream = new FileStream(documentFile.FileName ?? throw new InvalidOperationException("FileName is null"), FileMode.Open, FileAccess.Read); using var reader = new StreamReader(stream, Encoding.UTF8); var documentContent = new DocumentContent() { Code = reader.ReadToEnd() }; @@ -243,9 +243,9 @@ private void SaveCore(DocumentFile document, string fileName) document.FileName = fileName; document.ResetModified(); } - catch (Exception e) + catch (Exception ex) { - Trace.TraceError(e.ToString()); + Log.Default.Error("Save error: {0}", ex); messageService.ShowError(shellService.ShellView, Resources.SaveFileError, fileName); } } diff --git a/src/DotNetPad/DotNetPad.Domain/DocumentFile.cs b/src/DotNetPad/DotNetPad.Domain/DocumentFile.cs index c8741fb..c944f4f 100644 --- a/src/DotNetPad/DotNetPad.Domain/DocumentFile.cs +++ b/src/DotNetPad/DotNetPad.Domain/DocumentFile.cs @@ -58,7 +58,7 @@ public DocumentContent? Content } catch (Exception ex) { - Trace.TraceError(ex.ToString()); + Log.Default.Error("LoadContent error: {0}", ex); LoadError = ex; } diff --git a/src/DotNetPad/DotNetPad.Domain/Log.cs b/src/DotNetPad/DotNetPad.Domain/Log.cs index 1018e12..647a2c3 100644 --- a/src/DotNetPad/DotNetPad.Domain/Log.cs +++ b/src/DotNetPad/DotNetPad.Domain/Log.cs @@ -4,5 +4,5 @@ namespace Waf.DotNetPad.Domain; public static class Log { - public static TraceSource Default { get; } = new TraceSource("App"); + public static TraceSource Default { get; } = new("App"); } diff --git a/src/DotNetPad/DotNetPad.Domain/PerformanceTrace.cs b/src/DotNetPad/DotNetPad.Domain/PerformanceTrace.cs index e0cee55..068ba5a 100644 --- a/src/DotNetPad/DotNetPad.Domain/PerformanceTrace.cs +++ b/src/DotNetPad/DotNetPad.Domain/PerformanceTrace.cs @@ -10,5 +10,5 @@ public PerformanceTrace(string name, DocumentFile document) : this(document.File { } - public void Dispose() => Trace.WriteLine(">>> " + name + ": " + stopwatch.ElapsedMilliseconds + " ms"); + public void Dispose() => Log.Default.Trace(">>> {0}: {1} ms", name, stopwatch.ElapsedMilliseconds); } diff --git a/src/DotNetPad/DotNetPad.Presentation/App.xaml.cs b/src/DotNetPad/DotNetPad.Presentation/App.xaml.cs index db82b8d..f401b03 100644 --- a/src/DotNetPad/DotNetPad.Presentation/App.xaml.cs +++ b/src/DotNetPad/DotNetPad.Presentation/App.xaml.cs @@ -1,5 +1,6 @@ using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; +using System.Diagnostics; using System.Globalization; using System.Waf; using System.Waf.Applications; @@ -21,10 +22,13 @@ protected override void OnStartup(StartupEventArgs e) base.OnStartup(e); #if !DEBUG + Log.Default.Switch.Level = SourceLevels.Information; DispatcherUnhandledException += AppDispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException; +#else + Log.Default.Switch.Level = SourceLevels.Verbose; #endif - + Log.Default.Info("{0} {1} is starting; OS: {2}", ApplicationInfo.ProductName, ApplicationInfo.Version, Environment.OSVersion); catalog = new(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(WafConfiguration).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly)); @@ -46,6 +50,7 @@ protected override void OnExit(ExitEventArgs e) container.Dispose(); catalog.Dispose(); base.OnExit(e); + Log.Default.Info("{0} closed", ApplicationInfo.ProductName); } private static void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) => HandleException(e.Exception, false);