Skip to content

Commit

Permalink
Cleaner code (#49)
Browse files Browse the repository at this point in the history
This PR makes use of file scoped namespaces and Implicit Usings
  • Loading branch information
mburumaxwell authored Dec 25, 2021
1 parent 430efad commit e2ce83b
Show file tree
Hide file tree
Showing 107 changed files with 5,152 additions and 5,378 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# editorconfig.org

# top-most EditorConfig file
root = true

# CSharp formatting rules:
[*.cs]
csharp_style_namespace_declarations =file_scoped:warning
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<PropertyGroup>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</Compile>

<EmbeddedResource Update="Properties\Resources.resx">
<DesignTime>True</DesignTime>
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
Expand Down
62 changes: 27 additions & 35 deletions samples/LogAnalyticsSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,38 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace LogAnalyticsSample;

namespace LogAnalyticsSample
class Program
{
class Program
static async Task Main(string[] args)
{
static async Task Main(string[] args)
{
await Host.CreateDefaultBuilder(args)
.ConfigureLogging((context, loggingBuilder) =>
{
loggingBuilder.AddLogAnalytics(context.Configuration.GetSection("LogAnalytics"));
})
.ConfigureServices((context, services) =>
{
services.AddHostedService<TestService>();
})
.RunConsoleAsync();
}

await Host.CreateDefaultBuilder(args)
.ConfigureLogging((context, loggingBuilder) =>
{
loggingBuilder.AddLogAnalytics(context.Configuration.GetSection("LogAnalytics"));
})
.ConfigureServices((context, services) =>
{
services.AddHostedService<TestService>();
})
.RunConsoleAsync();
}

class TestService : BackgroundService
{
private readonly ILogger logger;
}

public TestService(ILogger<TestService> logger)
{
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
class TestService : BackgroundService
{
private readonly ILogger logger;

public TestService(ILogger<TestService> logger)
{
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
for (var i = 1; i <= 5; i++)
{
for (var i = 1; i <= 5; i++)
{
logger.LogInformation("In am working on something. Iteration {IterationNumber}", i);
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
logger.LogInformation("In am working on something. Iteration {IterationNumber}", i);
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
}
}
Loading

0 comments on commit e2ce83b

Please sign in to comment.