Skip to content

Commit

Permalink
Fixed various issues reported by EnableNETAnalyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot committed Oct 25, 2021
1 parent 8f37e28 commit 909797d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static NLogLoggerProvider Configure(this NLogLoggerProvider nlogProvider,
{
try
{
var result = Convert.ChangeType(configValue.Value, propertyInfo.PropertyType);
var result = Convert.ChangeType(configValue.Value, propertyInfo.PropertyType, System.Globalization.CultureInfo.InvariantCulture);
propertyInfo.SetMethod.Invoke(nlogProvider.Options, new[] { result });
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace NLog.Extensions.Logging
[ThreadAgnostic]
class MicrosoftConsoleLayoutRenderer : LayoutRenderer
{
private static readonly string[] EventIdMapper = Enumerable.Range(0, 50).Select(id => id.ToString()).ToArray();
private static readonly string[] EventIdMapper = Enumerable.Range(0, 50).Select(id => id.ToString(System.Globalization.CultureInfo.InvariantCulture)).ToArray();

/// <inheritdoc />
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
Expand All @@ -21,7 +21,7 @@ protected override void Append(StringBuilder builder, LogEventInfo logEvent)
builder.Append(microsoftLogLevel);
builder.Append(": ");
builder.Append(logEvent.LoggerName);
builder.Append("[");
builder.Append('[');
int eventId = 0;
if (logEvent.HasProperties && logEvent.Properties.TryGetValue("EventId_Id", out var eventIdValue))
{
Expand All @@ -35,7 +35,7 @@ protected override void Append(StringBuilder builder, LogEventInfo logEvent)
eventId = 0;
}
builder.Append(ConvertEventId(eventId));
builder.Append("]");
builder.Append(']');
builder.Append(System.Environment.NewLine);
builder.Append(" ");
builder.Append(logEvent.FormattedMessage);
Expand All @@ -53,7 +53,7 @@ static string ConvertEventId(int eventId)
else if (eventId > 0 || eventId < EventIdMapper.Length)
return EventIdMapper[eventId];
else
return eventId.ToString();
return eventId.ToString(System.Globalization.CultureInfo.InvariantCulture);
}

string ConvertLogLevel(LogLevel logLevel)
Expand Down
6 changes: 3 additions & 3 deletions src/NLog.Extensions.Logging/Logging/NLogLoggerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ protected virtual void Dispose(bool disposing)
}

/// <summary>
/// Creates a new <see cref="T:Microsoft.Extensions.Logging.ILogger" /> instance.
/// Creates a new <see cref="Microsoft.Extensions.Logging.ILogger" /> instance.
/// </summary>
/// <param name="categoryName">The logger name for messages produced by the logger.</param>
/// <returns>The <see cref="T:Microsoft.Extensions.Logging.ILogger" />.</returns>
/// <returns>The <see cref="Microsoft.Extensions.Logging.ILogger" />.</returns>
public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName)
{
lock (_loggers)
Expand All @@ -81,7 +81,7 @@ public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName)
/// <summary>
/// Do nothing
/// </summary>
/// <param name="provider">The <see cref="T:Microsoft.Extensions.Logging.ILoggerProvider" />.</param>
/// <param name="provider">The <see cref="Microsoft.Extensions.Logging.ILoggerProvider" />.</param>
public void AddProvider(ILoggerProvider provider)
{
InternalLogger.Debug("NLogLoggerFactory: AddProvider has been ignored {0}", provider?.GetType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace NLog.Extensions.Logging
internal class NLogMessageParameterList : IList<MessageTemplateParameter>
{
private readonly IReadOnlyList<KeyValuePair<string, object>> _parameterList;
private static readonly NLogMessageParameterList EmptyList = new NLogMessageParameterList(new KeyValuePair<string, object>[0]);
private static readonly NLogMessageParameterList EmptyList = new NLogMessageParameterList(Array.Empty<KeyValuePair<string, object>>());
private static readonly NLogMessageParameterList OriginalMessageList = new NLogMessageParameterList(new[] { new KeyValuePair<string, object>(NLogLogger.OriginalFormatPropertyName, string.Empty) });

private readonly int? _originalMessageIndex;
Expand Down

0 comments on commit 909797d

Please sign in to comment.