Skip to content
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

- fixes empty log file issue #4585

Merged
merged 1 commit into from
May 2, 2024
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
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);
}
}
Loading