Skip to content

Commit

Permalink
Updated Copyright and some minor formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaben committed Feb 1, 2017
1 parent 018b111 commit 25cff63
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 48 deletions.
1 change: 0 additions & 1 deletion Common.Logging.Serilog.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<iconUrl>http://serilog.net/images/serilog-nuget.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Easily bridge the old with the new and shiny: Common Logging adapter for Serilog structured logging.</description>
<releaseNotes>v3.1: Updated Common Logging and Serilog references.</releaseNotes>
<language>en-US</language>
<tags>serilog common logging adapter json structured</tags>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/CommonLoggingSerilogHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 CaptiveAire Systems
// Copyright 2014-2017 CaptiveAire Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
44 changes: 9 additions & 35 deletions src/SerilogCommonLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
namespace Common.Logging.Serilog
{
using System;
using System.Collections.Generic;
using System.Linq;

using global::Serilog;

Expand All @@ -26,43 +24,25 @@ namespace Common.Logging.Serilog
public class SerilogCommonLogger : ILog
{
readonly ILogger _logger;
private readonly SerilogPreformatter _preformatter;
readonly SerilogPreformatter _preformatter;

public SerilogCommonLogger(ILogger logger)
{
_logger = logger;
_preformatter = new SerilogPreformatter();
}

public bool IsDebugEnabled
{
get { return _logger.IsEnabled(LogLevel.Debug.ToSerilogEventLevel()); }
}
public bool IsDebugEnabled => this._logger.IsEnabled(LogLevel.Debug.ToSerilogEventLevel());

public bool IsErrorEnabled
{
get { return _logger.IsEnabled(LogLevel.Error.ToSerilogEventLevel()); }
}
public bool IsErrorEnabled => this._logger.IsEnabled(LogLevel.Error.ToSerilogEventLevel());

public bool IsFatalEnabled
{
get { return _logger.IsEnabled(LogLevel.Fatal.ToSerilogEventLevel()); }
}
public bool IsFatalEnabled => this._logger.IsEnabled(LogLevel.Fatal.ToSerilogEventLevel());

public bool IsInfoEnabled
{
get { return _logger.IsEnabled(LogLevel.Info.ToSerilogEventLevel()); }
}
public bool IsInfoEnabled => this._logger.IsEnabled(LogLevel.Info.ToSerilogEventLevel());

public bool IsTraceEnabled
{
get { return _logger.IsEnabled(LogLevel.Trace.ToSerilogEventLevel()); }
}
public bool IsTraceEnabled => this._logger.IsEnabled(LogLevel.Trace.ToSerilogEventLevel());

public bool IsWarnEnabled
{
get { return _logger.IsEnabled(LogLevel.Warn.ToSerilogEventLevel()); }
}
public bool IsWarnEnabled => this._logger.IsEnabled(LogLevel.Warn.ToSerilogEventLevel());

public virtual void Trace(object message)
{
Expand Down Expand Up @@ -612,17 +592,11 @@ protected void WriteFormat(LogLevel level, string message, object[] parameters)
/// <summary>
/// Returns the global context for variables
/// </summary>
public virtual IVariablesContext GlobalVariablesContext
{
get { return new Simple.NoOpVariablesContext(); }
}
public virtual IVariablesContext GlobalVariablesContext => new Simple.NoOpVariablesContext();

/// <summary>
/// Returns the thread-specific context for variables
/// </summary>
public virtual IVariablesContext ThreadVariablesContext
{
get { return new Simple.NoOpVariablesContext(); }
}
public virtual IVariablesContext ThreadVariablesContext => new Simple.NoOpVariablesContext();
}
}
2 changes: 1 addition & 1 deletion src/SerilogFactoryAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 CaptiveAire Systems
// Copyright 2014-2017 CaptiveAire Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
15 changes: 14 additions & 1 deletion src/SerilogInstanceWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
// Common.Logging.Serilog - Copyright (c) 2015 CaptiveAire
// Copyright 2014-2017 CaptiveAire Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


using System;
using System.Collections.Generic;
Expand Down
32 changes: 23 additions & 9 deletions src/SerilogPreformatter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
using System.Collections.Generic;
// Copyright 2014-2017 CaptiveAire Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand All @@ -7,7 +22,7 @@ namespace Common.Logging.Serilog
{
public class SerilogPreformatter
{
private readonly Regex _numericFormattedRegex = new Regex(@"{(\d{1,})}", RegexOptions.Compiled);
static readonly Regex _numericFormattedRegex = new Regex(@"{(\d{1,})}", RegexOptions.Compiled);

public bool TryPreformat(string templateString, object[] args, out string newTemplate, out object[] newArgs)
{
Expand All @@ -27,6 +42,7 @@ public bool TryPreformat(string templateString, object[] args, out string newTem
var templateBuilder = new StringBuilder(templateString);
var filteredArgs = new List<object>(args);
var matches = _numericFormattedRegex.Matches(templateString);

for (var i = matches.Count - 1; i >= 0; i--)
{
var currentMatcher = matches[i];
Expand All @@ -45,14 +61,12 @@ public bool TryPreformat(string templateString, object[] args, out string newTem
return true;
}

private static int GetArgumentPosition(Match currentMatcher)
static int GetArgumentPosition(Match currentMatcher)
{
var nummeric = currentMatcher.Groups
.OfType<Group>()
.Skip(1)
.First()
.Value;
return int.Parse(nummeric);
if (currentMatcher == null)
throw new ArgumentNullException(nameof(currentMatcher));

return int.Parse(currentMatcher.Groups.OfType<Group>().Skip(1).First().Value);
}
}
}

0 comments on commit 25cff63

Please sign in to comment.