public MessageTemplate Parse(string messageTemplate) { if (messageTemplate == null) { throw new ArgumentNullException(nameof(messageTemplate)); } if (messageTemplate.Length > MaxLengthOfTemplateToBeCached) { return(_messageTemplateParser.Parse(messageTemplate)); } if (_messageTemplateCache[messageTemplate.GetHashCode()] is MessageTemplate result) { return(result); } result = _messageTemplateParser.Parse(messageTemplate); lock (_messageTemplateLock) { if (_messageTemplateCache.Count >= MaxCacheItems) { ClearAndSyncMessageTemplateCache(); } _messageTemplateCache[messageTemplate.GetHashCode()] = result; } return(result); }
public void Write(IFormatProvider formatProvider, string format, params object[] args) { _lock.ThrowIfLocked(); var parsedTemplate = _templateParser.Parse(format); _templateWriter.Write(parsedTemplate, args, _coloredTextWriter, formatProvider); }
public MessageTemplate Parse(string messageTemplate) { if (messageTemplate == null) { throw new ArgumentNullException(nameof(messageTemplate)); } if (messageTemplate.Length > MaxCachedTemplateLength) { return(_innerParser.Parse(messageTemplate)); } #if HASHTABLE // ReSharper disable once InconsistentlySynchronizedField // ignored warning because this is by design var result = (MessageTemplate)_templates[messageTemplate]; if (result != null) { return(result); } #else MessageTemplate result; lock (_templatesLock) if (_templates.TryGetValue(messageTemplate, out result)) { return(result); } #endif result = _innerParser.Parse(messageTemplate); lock (_templatesLock) { // Exceeding MaxCacheItems is *not* the sunny day scenario; all we're doing here is preventing out-of-memory // conditions when the library is used incorrectly. Correct use (templates, rather than // direct message strings) should barely, if ever, overflow this cache. // Changing workloads through the lifecycle of an app instance mean we can gain some ground by // potentially dropping templates generated only in startup, or only during specific infrequent // activities. if (_templates.Count == MaxCacheItems) { _templates.Clear(); } _templates[messageTemplate] = result; } return(result); }
public MessageTemplate Parse(string messageTemplate) { if (messageTemplate == null) { throw new ArgumentNullException("messageTemplate"); } MessageTemplate result; lock (_templatesLock) if (_templates.TryGetValue(messageTemplate, out result)) { return(result); } result = _innerParser.Parse(messageTemplate); lock (_templatesLock) { // Exceeding MaxCacheItems is *not* the sunny day scenario; all we're doing here is preventing out-of-memory // conditions when the library is used incorrectly. Correct use (templates, rather than // direct message strings) should barely, if ever, overflow this cache. if (_templates.Count <= MaxCacheItems) { _templates[messageTemplate] = result; } } return(result); }
public MessageTemplate Parse(string messageTemplate) { if (messageTemplate == null) { throw new ArgumentNullException(nameof(messageTemplate)); } if (messageTemplate.Length > MaxCachedTemplateLength) { return(_innerParser.Parse(messageTemplate)); } if (_templates.TryGetValue(messageTemplate, out var result)) { return(result); } result = _innerParser.Parse(messageTemplate); { // Exceeding MaxCacheItems is *not* the sunny day scenario; all we're doing here is preventing out-of-memory // conditions when the library is used incorrectly. Correct use (templates, rather than // direct message strings) should barely, if ever, overflow this cache. // Changing workloads through the lifecycle of an app instance mean we can gain some ground by // potentially dropping templates generated only in startup, or only during specific infrequent // activities. if (_templates.Count == MaxCacheItems) { _templates.Clear(); } _templates[messageTemplate] = result; } return(result); }
public QueuedMessage GetMessage(string fromAddress = null, string fromName = null, string toAddress = null, string toName = null, string cc = null, string bcc = null) { var template = _messageTemplateProvider.GetMessageTemplate <T>(_site); if (template == null || template.IsDisabled) { return(null); } return(new QueuedMessage { FromAddress = _messageTemplateParser.Parse(fromAddress ?? template.FromAddress), FromName = _messageTemplateParser.Parse(fromName ?? template.FromName), ToAddress = _messageTemplateParser.Parse(toAddress ?? template.ToAddress), ToName = _messageTemplateParser.Parse(toName ?? template.ToName), Cc = _messageTemplateParser.Parse(cc ?? template.Cc), Bcc = _messageTemplateParser.Parse(bcc ?? template.Bcc), Subject = _messageTemplateParser.Parse(template.Subject), Body = _messageTemplateParser.Parse(template.Body), IsHtml = template.IsHtml }); }
public void Process(string messageTemplate, object[] messageTemplateParameters, out MessageTemplate parsedTemplate, out IEnumerable <LogEventProperty> properties) { parsedTemplate = _parser.Parse(messageTemplate); properties = _propertyBinder.ConstructProperties(parsedTemplate, messageTemplateParameters); }