Skip to content

Commit

Permalink
Fixed code issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Nov 18, 2024
1 parent 91d06ce commit 07a6847
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/Serilog.Sinks.ElmahIO/Sinks/ElmahIo/ElmahIoSinkOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using Serilog.Events;
using System;

#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace Serilog.Sinks.ElmahIo
#pragma warning restore IDE0130 // Namespace does not match folder structure
{
/// <summary>
/// Provides ElmahIoSink with configurable options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Elmah.Io.Client;
using System.Collections.Generic;

#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace Serilog.Sinks.ElmahIo
#pragma warning restore IDE0130 // Namespace does not match folder structure
{
internal static class KeyValuePairExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
using Serilog.Sinks.ElmahIo;
using Serilog.Sinks.PeriodicBatching;

#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace Serilog
#pragma warning restore IDE0130 // Namespace does not match folder structure
{
/// <summary>
/// Adds the WriteTo.ElmahIo() extension method to <see cref="LoggerConfiguration"/>.
Expand Down
4 changes: 3 additions & 1 deletion src/Serilog.Sinks.ElmahIo/Sinks/ElmahIo/ElmahIOSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
using Serilog.Events;
using Serilog.Sinks.PeriodicBatching;

#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace Serilog.Sinks.ElmahIo
#pragma warning restore IDE0130 // Namespace does not match folder structure
{
/// <summary>
/// Writes log events to the elmah.io service.
Expand Down Expand Up @@ -183,7 +185,7 @@ private static IList<Item> QueryString(LogEvent logEvent)
queryString.AddRange(result
.Query
.TrimStart('?')
.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries)
.Split(['&'], StringSplitOptions.RemoveEmptyEntries)
.Select(s =>
{
var splitted = s.Split('=');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net472;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<AssemblyName>Serilog.Sinks.ElmahIo.Tests</AssemblyName>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<LangVersion>9.0</LangVersion>
<LangVersion>12.0</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
55 changes: 27 additions & 28 deletions test/Serilog.Sinks.ElmahIo.Tests/Sinks/ElmahIo/ElmahIOSinkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
using NSubstitute;
using NUnit.Framework;
using Serilog.Events;
using Serilog.Parsing;

namespace Serilog.Sinks.ElmahIo.Tests
namespace Serilog.Sinks.ElmahIo.Tests.Sinks.ElmahIo
{
public class ElmahIoSinkTest
{
Expand Down Expand Up @@ -53,14 +52,14 @@ public async Task CanEmitCustomFields()
};

// Act
await sink.EmitBatchAsync(new List<LogEvent>
{
await sink.EmitBatchAsync(
[
new(
Now,
LogEventLevel.Error,
null,
new MessageTemplate("{type} {hostname} {application} {user} {source} {method} {version} {url} {statusCode}", new List<MessageTemplateToken>()), new List<LogEventProperty>
{
new MessageTemplate("{type} {hostname} {application} {user} {source} {method} {version} {url} {statusCode}", []),
[
new("type", new ScalarValue("type")),
new("hostname", new ScalarValue("hostname")),
new("application", new ScalarValue("application")),
Expand All @@ -76,9 +75,9 @@ await sink.EmitBatchAsync(new List<LogEvent>
new("cookies", new DictionaryValue(cookies)),
new("form", new DictionaryValue(form)),
new("queryString", new DictionaryValue(queryString)),
}
]
)
});
]);

// Assert
Assert.That(loggedMessages != null);
Expand Down Expand Up @@ -114,18 +113,18 @@ public async Task CanEmit()
Thread.CurrentPrincipal = principalMock;

// Act
await sink.EmitBatchAsync(new List<LogEvent>
{
await sink.EmitBatchAsync(
[
new(
Now,
LogEventLevel.Error,
exception,
new MessageTemplate("Simple test", new List<MessageTemplateToken>()), new List<LogEventProperty>
{
new MessageTemplate("Simple test", []),
[
new("name", new ScalarValue("value"))
}
]
)
});
]);

// Assert
Assert.That(loggedMessages != null);
Expand Down Expand Up @@ -153,10 +152,10 @@ public async Task CanEmitApplicationFromOptions()
var sink = new ElmahIoSink(new ElmahIoSinkOptions(string.Empty, Guid.Empty) { Application = "MyApp" }, clientMock);

// Act
await sink.EmitBatchAsync(new List<LogEvent>
{
new(Now, LogEventLevel.Information, null, new MessageTemplate("Hello World", new List<MessageTemplateToken>()), new List<LogEventProperty>())
});
await sink.EmitBatchAsync(
[
new(Now, LogEventLevel.Information, null, new MessageTemplate("Hello World", []), [])
]);

// Assert
Assert.That(loggedMessages != null);
Expand All @@ -172,18 +171,18 @@ public async Task CanEmitCategoryFromSourceContext()
var sink = new ElmahIoSink(new ElmahIoSinkOptions(string.Empty, Guid.Empty), clientMock);

// Act
await sink.EmitBatchAsync(new List<LogEvent>
{
await sink.EmitBatchAsync(
[
new(
Now,
LogEventLevel.Error,
null,
new MessageTemplate("Test", new List<MessageTemplateToken>()), new List<LogEventProperty>
{
new MessageTemplate("Test", []),
[
new("SourceContext", new ScalarValue("category")),
}
]
)
});
]);

// Assert
Assert.That(loggedMessages != null);
Expand All @@ -205,10 +204,10 @@ public async Task CanFilterBatchFromOptions()
var sink = new ElmahIoSink(options);

// Act
await sink.EmitBatchAsync(new List<LogEvent>
{
new(Now, LogEventLevel.Error, null, new MessageTemplate("Test1", new List<MessageTemplateToken>()), new List<LogEventProperty>())
});
await sink.EmitBatchAsync(
[
new(Now, LogEventLevel.Error, null, new MessageTemplate("Test1", []), [])
]);

// Assert
Assert.That(messages, Is.EqualTo(0));
Expand Down

0 comments on commit 07a6847

Please sign in to comment.