Skip to content

Commit

Permalink
♻️ Replaced all Debug.WriteLine for Trace.WriteLine (#1311)
Browse files Browse the repository at this point in the history
replaced all Debug.WriteLine for Trace.WriteLine
  • Loading branch information
pictos authored Jul 30, 2023
1 parent bf69c6f commit 172a1e7
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ Here we will have some:

## Contributing Code - Best Practices

### Debug Logging
* Always use `Trace.WriteLine()` instead of `Debug.WriteLine` for debug logging because `Debug.WriteLine` is removed by the compiler in Release builds

### Enums
* Always use `Unknown` at index 0 for return types that may have a value that is not known
* Always use `Default` at index 0 for option types that can use the system default option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ public void SetCount(uint count)
var packageName = Application.Context.PackageName;
if (packageName is null)
{
Debug.WriteLine("Unable to get package name");
Trace.WriteLine("Unable to get package name");
return;
}

var component = Application.Context.PackageManager?.GetLaunchIntentForPackage(packageName)?.Component;
if (component is null)
{
Debug.WriteLine($"Unable to get launch intent component for package {packageName}");
Trace.WriteLine($"Unable to get launch intent component for package {packageName}");
return;
}

if (!CanSetBadgeCounter())
{
Debug.WriteLine("Current launcher doesn't support badge counter");
Trace.WriteLine("Current launcher doesn't support badge counter");
return;
}

Expand All @@ -40,7 +40,7 @@ public void SetCount(uint count)
}
catch (Exception ex)
{
Debug.WriteLine($"{nameof(DefaultBadgeProvider)} unable to set badge count: " + ex.Message);
Trace.WriteLine($"{nameof(DefaultBadgeProvider)} unable to set badge count: " + ex.Message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void SetCount(uint count)
{
if (error is not null)
{
Debug.WriteLine($"Error Requesting Authorization to Set Badge Count: {error.Description}");
Trace.WriteLine($"Error Requesting Authorization to Set Badge Count: {error.Description}");
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static bool IsSupported()
return true;
}

System.Diagnostics.Debug.WriteLine($"This functionality is not available. Minimum supported API is {(int)BuildVersionCodes.M}");
System.Diagnostics.Trace.WriteLine($"This functionality is not available. Minimum supported API is {(int)BuildVersionCodes.M}");
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Initialize()
}
else
{
System.Diagnostics.Debug.WriteLine("DrawingView requires Windows 10.0.18362 or higher.");
System.Diagnostics.Trace.WriteLine("DrawingView requires Windows 10.0.18362 or higher.");
}

Lines.CollectionChanged += OnLinesCollectionChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace {{textStyleClassMetadata.Namespace}};
{
//When creating an Animation too early in the lifecycle of the Page, i.e. in the OnAppearing method,
//the Page might not have an 'IAnimationManager' yet, resulting in an ArgumentException.
System.Diagnostics.Debug.WriteLine($"{aex.GetType().Name} thrown in {typeof(ColorAnimationExtensions_{{textStyleClassMetadata.ClassName}}).FullName}: {aex.Message}");
System.Diagnostics.Trace.WriteLine($"{aex.GetType().Name} thrown in {typeof(ColorAnimationExtensions_{{textStyleClassMetadata.ClassName}}).FullName}: {aex.Message}");
animationCompletionSource.SetResult(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public bool CanChangeState
}
}

Command ChangeStateCommand => changeStateCommand ??= new Command(() => Debug.WriteLine("Command Tapped"), () => CanChangeState);
Command ChangeStateCommand => changeStateCommand ??= new Command(() => Trace.WriteLine("Command Tapped"), () => CanChangeState);

public event PropertyChangedEventHandler? PropertyChanged;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Task OnAnimate()
}
catch (Exception ex) when (Options.ShouldSuppressExceptionsInAnimations)
{
Debug.WriteLine(ex);
Trace.WriteLine(ex);
return Task.CompletedTask;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/CommunityToolkit.Maui/Behaviors/BaseBehavior.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void OnViewPropertyChanged(object? sender, PropertyChangedEventArgs e)
}
catch (Exception ex) when (Options.ShouldSuppressExceptionsInBehaviors)
{
Debug.WriteLine(ex);
Trace.WriteLine(ex);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override void OnDetachingFrom(Grid bindable)

static void LogWarning(string warning, bool shouldThrowException)
{
System.Diagnostics.Debug.WriteLine(warning);
System.Diagnostics.Trace.WriteLine(warning);

if (shouldThrowException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ async ValueTask UpdateStateAsync(VisualElement? view, ValidationFlags flags, boo
IsValid = false;
IsRunning = false;

Debug.WriteLine(ex);
Trace.WriteLine(ex);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public abstract class BaseConverter<TFrom, TTo, TParam> : ValueConverterExtensio
}
catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters)
{
Debug.WriteLine(ex);
Trace.WriteLine(ex);
return DefaultConvertBackReturnValue;
}
}
Expand All @@ -89,7 +89,7 @@ public abstract class BaseConverter<TFrom, TTo, TParam> : ValueConverterExtensio
}
catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters)
{
Debug.WriteLine(ex);
Trace.WriteLine(ex);
return DefaultConvertReturnValue;
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public abstract class BaseConverter<TFrom, TTo> : ValueConverterExtension, IComm
}
catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters)
{
Debug.WriteLine(ex);
Trace.WriteLine(ex);
return DefaultConvertBackReturnValue;
}
}
Expand All @@ -170,7 +170,7 @@ public abstract class BaseConverter<TFrom, TTo> : ValueConverterExtension, IComm
}
catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters)
{
Debug.WriteLine(ex);
Trace.WriteLine(ex);
return DefaultConvertReturnValue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Task<bool> BackgroundColorTo(this VisualElement element, Color col
{
//When creating an Animation too early in the lifecycle of the Page, i.e. in the OnAppearing method,
//the Page might not have an 'IAnimationManager' yet, resulting in an ArgumentException.
System.Diagnostics.Debug.WriteLine($"{aex.GetType().Name} thrown in {typeof(ColorAnimationExtensions).FullName}: {aex.Message}");
System.Diagnostics.Trace.WriteLine($"{aex.GetType().Name} thrown in {typeof(ColorAnimationExtensions).FullName}: {aex.Message}");
animationCompletionSource.SetResult(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static async Task<Stream> DownloadStreamAsync(this HttpClient client, Uri
}
catch (Exception ex)
{
Debug.WriteLine($"Error getting stream for {uri}: {ex}");
Trace.WriteLine($"Error getting stream for {uri}: {ex}");
return Stream.Null;
}
}
Expand Down

0 comments on commit 172a1e7

Please sign in to comment.