diff --git a/src/Serilog/Parsing/MessageTemplateParser.cs b/src/Serilog/Parsing/MessageTemplateParser.cs index 7a9e1003c..644697e60 100644 --- a/src/Serilog/Parsing/MessageTemplateParser.cs +++ b/src/Serilog/Parsing/MessageTemplateParser.cs @@ -133,11 +133,8 @@ static MessageTemplateToken ParsePropertyToken(int startAt, string messageTempla if (lastDash > 0) return new TextToken(rawText, first); - var width = lastDash == -1 ? - int.Parse(alignment) : - int.Parse(alignment.Substring(1)); - - if (width == 0) + var width = 0; + if (!int.TryParse(lastDash == -1 ? alignment : alignment.Substring(1), out width) || width == 0) return new TextToken(rawText, first); var direction = lastDash == -1 ?