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

Commit

Permalink
count
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy committed Mar 13, 2017
1 parent a428655 commit 2c81564
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;

namespace Microsoft.Extensions.Logging.Internal
{
Expand All @@ -19,13 +20,14 @@ public class FormattedLogValues : IReadOnlyList<KeyValuePair<string, object>>
private readonly LogValuesFormatter _formatter;
private readonly object[] _values;
private readonly string _originalMessage;
private static int _count;
private const int MaxCachedFormatters = 1024;

public FormattedLogValues(string format, params object[] values)
{
if (values?.Length != 0 && format != null)
{
if (_formatters.Count >= MaxCachedFormatters)
if (_count >= MaxCachedFormatters)
{
if (!_formatters.TryGetValue(format, out _formatter))
{
Expand All @@ -34,7 +36,11 @@ public FormattedLogValues(string format, params object[] values)
}
else
{
_formatter = _formatters.GetOrAdd(format, f => new LogValuesFormatter(f));
_formatter = _formatters.GetOrAdd(format, f =>
{
Interlocked.Increment(ref _count);
return new LogValuesFormatter(f);
});
}
}

Expand Down

0 comments on commit 2c81564

Please sign in to comment.