Skip to content

Commit 969fdf8

Browse files
Merge pull request #16 from nullinside-development-group/feat/log4net
feat: adding log4net
2 parents 50521d5 + 5a5f4a2 commit 969fdf8

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,6 @@ $RECYCLE.BIN/
133133
_NCrunch*
134134
.idea
135135

136-
launchSettings.json
136+
launchSettings.json
137+
138+
.vs

src/Nullinside.Cicd.GitHub/Nullinside.Cicd.GitHub.csproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="log4net" Version="3.0.4"/>
23-
<PackageReference Include="Octokit" Version="14.0.0"/>
22+
<PackageReference Include="log4net" Version="3.0.4" />
23+
<PackageReference Include="log4net.Ext.Json" Version="3.0.3" />
24+
<PackageReference Include="Octokit" Version="14.0.0" />
2425
</ItemGroup>
2526

2627
<ItemGroup>
27-
<ProjectReference Include="..\octokit.graphql.net\src\Octokit.GraphQL\Octokit.GraphQL.csproj"/>
28+
<ProjectReference Include="..\octokit.graphql.net\src\Octokit.GraphQL\Octokit.GraphQL.csproj" />
29+
</ItemGroup>
30+
31+
<ItemGroup>
32+
<None Remove="log4net.config" />
33+
<Content Include="log4net.config">
34+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
35+
</Content>
2836
</ItemGroup>
2937

3038
</Project>

src/Nullinside.Cicd.GitHub/Program.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// See https://aka.ms/new-console-template for more information
22

3+
using log4net;
4+
using log4net.Config;
5+
using log4net.Core;
6+
37
using Nullinside.Cicd.GitHub;
48
using Nullinside.Cicd.GitHub.Rule;
59

@@ -11,6 +15,9 @@
1115
using ProductHeaderValue = Octokit.ProductHeaderValue;
1216
using Query = Octokit.GraphQL.Query;
1317

18+
XmlConfigurator.Configure(new FileInfo("log4net.config"));
19+
var log = LogManager.GetLogger(typeof(Program));
20+
1421
IRepoRule?[] rules = AppDomain.CurrentDomain.GetAssemblies()
1522
.SelectMany(a => a.GetTypes())
1623
.Where(t => typeof(IRepoRule).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface)
@@ -42,6 +49,6 @@
4249
}
4350
}
4451

45-
Console.WriteLine("Waiting for next execution time...");
52+
log.Info("Waiting for next execution time...");
4653
Task.WaitAll(Task.Delay(TimeSpan.FromMinutes(5)));
4754
}

src/Nullinside.Cicd.GitHub/Rule/AssociateIssuesWithProject.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Octokit;
1+
using log4net;
2+
3+
using Octokit;
24
using Octokit.GraphQL;
35
using Octokit.GraphQL.Core;
46
using Octokit.GraphQL.Model;
@@ -12,6 +14,11 @@ namespace Nullinside.Cicd.GitHub.Rule;
1214
/// Handles associating issues with the project automatically.
1315
/// </summary>
1416
public class AssociateIssuesWithProject : IRepoRule {
17+
/// <summary>
18+
/// The logger
19+
/// </summary>
20+
private ILog _log = LogManager.GetLogger(typeof(AssociateIssuesWithProject));
21+
1522
/// <inheritdoc />
1623
public async Task Handle(GitHubClient client, Connection graphQl, ID projectId, Repository repo) {
1724
if (!repo.HasIssues) {
@@ -36,7 +43,7 @@ public async Task Handle(GitHubClient client, Connection graphQl, ID projectId,
3643
continue;
3744
}
3845

39-
Console.WriteLine($"{repo.Name}: Associating issue #{issue.Number}");
46+
_log.Info($"{repo.Name}: Associating issue #{issue.Number}");
4047
await graphQl.Run(new Mutation()
4148
.AddProjectV2ItemById(new Arg<AddProjectV2ItemByIdInput>(new AddProjectV2ItemByIdInput {
4249
ProjectId = projectId,

src/Nullinside.Cicd.GitHub/Rule/CreateRulesets.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Octokit;
1+
using log4net;
2+
3+
using Octokit;
24
using Octokit.GraphQL;
35
using Octokit.GraphQL.Core;
46
using Octokit.GraphQL.Model;
@@ -12,6 +14,11 @@ namespace Nullinside.Cicd.GitHub.Rule;
1214
/// Creates the branch merging rules based on the code bases' language.
1315
/// </summary>
1416
public class CreateRulesets : IRepoRule {
17+
/// <summary>
18+
/// The logger
19+
/// </summary>
20+
private ILog _log = LogManager.GetLogger(typeof(CreateRulesets));
21+
1522
/// <inheritdoc />
1623
public async Task Handle(GitHubClient client, Connection graphQl, ID projectId, Repository repo) {
1724
// This currently doesn't run properly. You get an error about not specifying multiple Parameters on the status
@@ -33,7 +40,7 @@ public async Task Handle(GitHubClient client, Connection graphQl, ID projectId,
3340
.Repository(repo.Name, Constants.GITHUB_ORG)
3441
.Select(i => i.Id));
3542

36-
Console.WriteLine($"{repo.Name}: Creating default ruleset");
43+
_log.Info($"{repo.Name}: Creating default ruleset");
3744
StatusCheckConfigurationInput[]? statusChecks = null;
3845
if ("Typescript".Equals(repo.Language, StringComparison.InvariantCultureIgnoreCase)) {
3946
statusChecks = new[] {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<log4net>
2+
<appender name="ConsoleAppenderJson" type="log4net.Appender.ConsoleAppender">
3+
<layout type='log4net.Layout.SerializedLayout, log4net.Ext.Json'>
4+
<decorator type='log4net.Layout.Decorators.StandardTypesDecorator, log4net.Ext.Json'/>
5+
<default/> <!--explicit default members-->
6+
<remove value='message'/> <!--remove the default preformatted message member-->
7+
<member value='message:messageobject'/> <!--add raw message-->
8+
</layout>
9+
10+
</appender>
11+
12+
<root>
13+
<level value="INFO"/>
14+
<appender-ref ref="ConsoleAppenderJson"/>
15+
</root>
16+
</log4net>

0 commit comments

Comments
 (0)