From 5a5f4a2ab8f257e42721badfaf019cc87a82c139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88?= Date: Tue, 6 May 2025 13:28:05 -0400 Subject: [PATCH] feat: adding log4net --- .gitignore | 4 +++- .../Nullinside.Cicd.GitHub.csproj | 14 +++++++++++--- src/Nullinside.Cicd.GitHub/Program.cs | 9 ++++++++- .../Rule/AssociateIssuesWithProject.cs | 11 +++++++++-- .../Rule/CreateRulesets.cs | 11 +++++++++-- src/Nullinside.Cicd.GitHub/log4net.config | 16 ++++++++++++++++ 6 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 src/Nullinside.Cicd.GitHub/log4net.config diff --git a/.gitignore b/.gitignore index 63cbbd2..3c530c6 100644 --- a/.gitignore +++ b/.gitignore @@ -133,4 +133,6 @@ $RECYCLE.BIN/ _NCrunch* .idea -launchSettings.json \ No newline at end of file +launchSettings.json + +.vs \ No newline at end of file diff --git a/src/Nullinside.Cicd.GitHub/Nullinside.Cicd.GitHub.csproj b/src/Nullinside.Cicd.GitHub/Nullinside.Cicd.GitHub.csproj index f0b7cd4..7ef8816 100644 --- a/src/Nullinside.Cicd.GitHub/Nullinside.Cicd.GitHub.csproj +++ b/src/Nullinside.Cicd.GitHub/Nullinside.Cicd.GitHub.csproj @@ -19,12 +19,20 @@ - - + + + - + + + + + + + Always + diff --git a/src/Nullinside.Cicd.GitHub/Program.cs b/src/Nullinside.Cicd.GitHub/Program.cs index afb9fca..1f63f76 100644 --- a/src/Nullinside.Cicd.GitHub/Program.cs +++ b/src/Nullinside.Cicd.GitHub/Program.cs @@ -1,5 +1,9 @@ // See https://aka.ms/new-console-template for more information +using log4net; +using log4net.Config; +using log4net.Core; + using Nullinside.Cicd.GitHub; using Nullinside.Cicd.GitHub.Rule; @@ -11,6 +15,9 @@ using ProductHeaderValue = Octokit.ProductHeaderValue; using Query = Octokit.GraphQL.Query; +XmlConfigurator.Configure(new FileInfo("log4net.config")); +var log = LogManager.GetLogger(typeof(Program)); + IRepoRule?[] rules = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(a => a.GetTypes()) .Where(t => typeof(IRepoRule).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface) @@ -42,6 +49,6 @@ } } - Console.WriteLine("Waiting for next execution time..."); + log.Info("Waiting for next execution time..."); Task.WaitAll(Task.Delay(TimeSpan.FromMinutes(5))); } \ No newline at end of file diff --git a/src/Nullinside.Cicd.GitHub/Rule/AssociateIssuesWithProject.cs b/src/Nullinside.Cicd.GitHub/Rule/AssociateIssuesWithProject.cs index b7185ae..9bea242 100644 --- a/src/Nullinside.Cicd.GitHub/Rule/AssociateIssuesWithProject.cs +++ b/src/Nullinside.Cicd.GitHub/Rule/AssociateIssuesWithProject.cs @@ -1,4 +1,6 @@ -using Octokit; +using log4net; + +using Octokit; using Octokit.GraphQL; using Octokit.GraphQL.Core; using Octokit.GraphQL.Model; @@ -12,6 +14,11 @@ namespace Nullinside.Cicd.GitHub.Rule; /// Handles associating issues with the project automatically. /// public class AssociateIssuesWithProject : IRepoRule { + /// + /// The logger + /// + private ILog _log = LogManager.GetLogger(typeof(AssociateIssuesWithProject)); + /// public async Task Handle(GitHubClient client, Connection graphQl, ID projectId, Repository repo) { if (!repo.HasIssues) { @@ -36,7 +43,7 @@ public async Task Handle(GitHubClient client, Connection graphQl, ID projectId, continue; } - Console.WriteLine($"{repo.Name}: Associating issue #{issue.Number}"); + _log.Info($"{repo.Name}: Associating issue #{issue.Number}"); await graphQl.Run(new Mutation() .AddProjectV2ItemById(new Arg(new AddProjectV2ItemByIdInput { ProjectId = projectId, diff --git a/src/Nullinside.Cicd.GitHub/Rule/CreateRulesets.cs b/src/Nullinside.Cicd.GitHub/Rule/CreateRulesets.cs index f7e488a..336553e 100644 --- a/src/Nullinside.Cicd.GitHub/Rule/CreateRulesets.cs +++ b/src/Nullinside.Cicd.GitHub/Rule/CreateRulesets.cs @@ -1,4 +1,6 @@ -using Octokit; +using log4net; + +using Octokit; using Octokit.GraphQL; using Octokit.GraphQL.Core; using Octokit.GraphQL.Model; @@ -12,6 +14,11 @@ namespace Nullinside.Cicd.GitHub.Rule; /// Creates the branch merging rules based on the code bases' language. /// public class CreateRulesets : IRepoRule { + /// + /// The logger + /// + private ILog _log = LogManager.GetLogger(typeof(CreateRulesets)); + /// public async Task Handle(GitHubClient client, Connection graphQl, ID projectId, Repository repo) { // 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, .Repository(repo.Name, Constants.GITHUB_ORG) .Select(i => i.Id)); - Console.WriteLine($"{repo.Name}: Creating default ruleset"); + _log.Info($"{repo.Name}: Creating default ruleset"); StatusCheckConfigurationInput[]? statusChecks = null; if ("Typescript".Equals(repo.Language, StringComparison.InvariantCultureIgnoreCase)) { statusChecks = new[] { diff --git a/src/Nullinside.Cicd.GitHub/log4net.config b/src/Nullinside.Cicd.GitHub/log4net.config new file mode 100644 index 0000000..1cdfafa --- /dev/null +++ b/src/Nullinside.Cicd.GitHub/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file