Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Option 2: Just cap
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy committed Feb 21, 2017
1 parent 5ba5fd4 commit 5e9d398
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 239 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;

namespace Microsoft.Extensions.Logging.Internal
Expand All @@ -14,16 +15,27 @@ namespace Microsoft.Extensions.Logging.Internal
public class FormattedLogValues : IReadOnlyList<KeyValuePair<string, object>>
{
private const string NullFormat = "[null]";
private static ConcurrentLruCache<string, LogValuesFormatter> _formatters = new ConcurrentLruCache<string, LogValuesFormatter>(1024);
private static ConcurrentDictionary<string, LogValuesFormatter> _formatters = new ConcurrentDictionary<string, LogValuesFormatter>();
private readonly LogValuesFormatter _formatter;
private readonly object[] _values;
private readonly string _originalMessage;
private const int MaxCachedFormatters = 1024;

public FormattedLogValues(string format, params object[] values)
{
if (values?.Length != 0 && format != null)
{
_formatter = _formatters.GetOrAdd(format, format, f => new LogValuesFormatter(f));
if (_formatters.Count >= MaxCachedFormatters)
{
if (!_formatters.TryGetValue(format, out _formatter))
{
_formatter = new LogValuesFormatter(format);
}
}
else
{
_formatter = _formatters.GetOrAdd(format, f => new LogValuesFormatter(f));
}
}

_originalMessage = format ?? NullFormat;
Expand Down

0 comments on commit 5e9d398

Please sign in to comment.