Skip to content

Commit

Permalink
- fixes empty log file issue
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed May 1, 2024
1 parent 89d7680 commit ff534e5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Fixed a bug where TypeScript deserialization would fail on Uppercase properties.[#4479](https://github.com/microsoft/kiota/issues/4479)
- Fixed a bug where clients and plugins generation would leave empty log files. [#4584](https://github.com/microsoft/kiota/issues/4584)
- Changed URI template generation to reuse templates when required templates are absent across operations.
- Fixed path deduplication logic to avoid double `Id` suffixes in indexer names in scenarios where the `Id` suffix is already present.[#4519](https://github.com/microsoft/kiota/issues/4519)
- Fixed path deduplication logic to avoid double `Id` suffixes in indexer names in scenarios where the `Id` suffix is already present.[#4519](https://github.com/microsoft/kiota/issues/4519)
- Updated reserved name providers for Java and Php so that "object" can be escaped.
- Fixes request builder disambiguation when child nodes had different prefixes for different paths with same parameters.[#4448](https://github.com/microsoft/kiota/issues/4448)
- Fixes request builder disambiguation when child nodes had different prefixes for different paths with same parameters.[#4448](https://github.com/microsoft/kiota/issues/4448)
- Do not generate CS8603 warnings when enabling backing store in CSharp generation.
- Fixed excluding operation. [#4399](https://github.com/microsoft/kiota/issues/4399)
- Fixed plugin generation of `ApiManifest` type to not include the `x-ms-kiota-hash` in the generated plugin. [#4561](https://github.com/microsoft/kiota/issues/4561)
Expand Down
12 changes: 10 additions & 2 deletions src/kiota/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ static async Task<int> Main(string[] args)
{
var rootCommand = KiotaHost.GetRootCommand();
var result = await rootCommand.InvokeAsync(args);
foreach (var subCommand in rootCommand.Subcommands.Select(static x => x.Handler).OfType<IDisposable>())
subCommand.Dispose();
DisposeSubCommands(rootCommand);
return result;
}
private static void DisposeSubCommands(this Command command)
{
if (command.Handler is IDisposable disposableHandler)
disposableHandler.Dispose();
foreach (var subCommand in command.Subcommands)
{
DisposeSubCommands(subCommand);
}
}
}
40 changes: 40 additions & 0 deletions tests/Kiota.Builder.Tests/Logging/FileLoggerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.IO;
using Kiota.Builder.Logging;
using Microsoft.Extensions.Logging;
using Xunit;

namespace Kiota.Builder.Tests.Logging;

public sealed class FileLoggerTests : IDisposable
{
private readonly string _logDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
public FileLoggerTests()
{
Directory.CreateDirectory(_logDirectory);
}
[Fact]
public void CleansUpFileWhenNoLogs()
{
using (var logger = new FileLogLogger(_logDirectory, LogLevel.Warning, "test"))
{ //using this format intentionally to ensure the dispose is called before the assert
logger.LogInformation("test");
}
Assert.False(File.Exists(Path.Combine(_logDirectory, FileLogLogger.LogFileName)));
}
[Fact]
public void KeepsLogFileWhenLogs()
{
using (var logger = new FileLogLogger(_logDirectory, LogLevel.Warning, "test"))
{ //using this format intentionally to ensure the dispose is called before the assert
logger.LogWarning("test");
}
Assert.True(File.Exists(Path.Combine(_logDirectory, FileLogLogger.LogFileName)));
}

public void Dispose()
{
if (Directory.Exists(_logDirectory))
Directory.Delete(_logDirectory, true);
}
}

0 comments on commit ff534e5

Please sign in to comment.