I don't think interpolated strings work for variable strings. Format still exists in C# too. But of most logging features can be made by far safer, especially knowing that a lot of logging happens on very rare occasions, resulting in extremely hard-to detect bugs, especially on platforms like Android where getting the crashlog from a user (even if using the despicable remote telemetry) is by far less trivial.
But constructing basic log messages usually looks like this (not pure C# but Unity):
Debug.Log($"{name} was pressed {events.count} times");Where "$" symbol means "interpolated string", so it looks for those curly brackets. Under the hood it just asks for
name.ToString() and
count.ToString().
Also helps a lot with issue when parameters while match the type don't match the content because it's much more "human-readable" than need to count the amount of
%s and make sure that 7th corresponds to
Self.ClassName.
With my most regular error would be:
Label1.Caption := Format('%s was pressed %d times', [Events.Count, Button1.Name]);which can go undetected for multiple versions of the app and lead to rare, apparently random but persistent crashes. Forcing me to wrap literally everything inside of
try..except just to make sure that at least some hint will be displayed about where the crash occurred. E.g. debugging this crash took me almost a week:
if (ToX <= 0) or (ToY <=0) or (ToX >= Map.PredSizeX) or (ToY >= Map.PredSizeY) then
begin
ShowError('%s is trying to teleport to broken coordinates (%d, %d) on map %dx%d. Teleporting to random point instead.', [ClassName, ToX, ToY, Map.SizeX, Map.SizeY]);
TeleportToRandomPoint;
Exit;
end;
Yes, you've guessed correctly there are two versions of the procedure and one of them has
ToX, ToY as
Single, but I've forgotten about that while copy-pasting the error message when I was adding the
Single version of the procedure, so it crashes the whole game trying to convert them to
%d, %d and as the crash was reported from Android, go figure... Detecting such typos at compile time could have been so much more convenient.