Skip to content

Enable <Nullable> in PingPonger.csproj and address warnings #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PingPonger/PingPonger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog.Sinks.ColoredConsole" Version="3.0.1"/>
Expand Down
11 changes: 5 additions & 6 deletions PingPonger/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ internal class Options

[Option('i', "ip", Required = false,
HelpText = "IP to send to")]
public string IP { get; set; }
public string? IP { get; set; }

[Option('l', "url", Required = false,
HelpText = "URL to send to")]
public string Url { get; set; }
public string? Url { get; set; }

[Option('p', "port", Required = false,
HelpText = "the Port to send to")]
Expand Down Expand Up @@ -60,7 +60,7 @@ public static int Main(string[] args)

logConfig.WriteTo.ColoredConsole();

if (options.Url.Length > 0)
if (options.Url?.Length > 0)
{
if (options.UDP)
{
Expand All @@ -71,10 +71,9 @@ public static int Main(string[] args)
logConfig.WriteTo.TCPSink(options.Url, options.Port, null, null, new LogstashJsonFormatter());
}
}
else if (options.IP.Length > 0)
else if (options.IP?.Length > 0)
{
IPAddress ipAddress;
if (!IPAddress.TryParse(options.IP, out ipAddress))
if (!IPAddress.TryParse(options.IP, out var ipAddress))
{
Console.WriteLine("Could not parse " + options.IP + " as an IP address");
return 1;
Expand Down
4 changes: 2 additions & 2 deletions Serilog.Sinks.Network/Sinks/TCP/TCPSocketWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private async Task Run(Func<Task<Stream?>> tryOpenStream)
}
}

private async Task FlushQueue(string entry)
private async Task FlushQueue(string? entry)
{
while (_eventQueue.Count > 0)
{
Expand Down Expand Up @@ -285,7 +285,7 @@ public class ExponentialBackoffTcpReconnectionPolicy
{
private const int Ceiling = 10 * 60; // 10 minutes in seconds

public static async Task<Stream> ConnectAsync(Func<Uri, Task<Stream>> connect, Uri host,
public static async Task<Stream?> ConnectAsync(Func<Uri, Task<Stream>> connect, Uri host,
CancellationToken cancellationToken)
{
int delay = 1; // in seconds
Expand Down