Skip to content

Commit

Permalink
fixed logging errors
Browse files Browse the repository at this point in the history
  • Loading branch information
iNoles committed Oct 22, 2024
1 parent a1a4f6e commit 5e458d1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions HackerNews.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="FirebaseDatabase.net" Version="4.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
Expand Down
22 changes: 20 additions & 2 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
namespace HackerNews;
using Microsoft.Extensions.Logging;

namespace HackerNews;

public partial class MainPage
{
private readonly NewsViewModel _newsViewModel = new();
private readonly NewsViewModel _newsViewModel;

public MainPage()
{
InitializeComponent();

// Set up the logger
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole(); // Add other logging providers as necessary
});

var logger = loggerFactory.CreateLogger<NewsViewModel>();

// Create an instance of NewsService, passing the loggerFactory if needed
var newsService = new NewsService(loggerFactory);

// Create the NewsViewModel instance
_newsViewModel = new NewsViewModel(newsService, logger);

// Set the ItemsSource for the NewsListView
NewsListView.ItemsSource = _newsViewModel.TopStoryCollection;
}

Expand Down
5 changes: 3 additions & 2 deletions NewsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

namespace HackerNews;

public class NewsService(ILogger<NewsService> logger)
public class NewsService(ILoggerFactory loggerFactory)
{
private const string FirebaseDatabaseUrl = "https://hacker-news.firebaseio.com/v0/";
private readonly FirebaseClient _firebaseClient = new(FirebaseDatabaseUrl);
private readonly ILogger<NewsService> _logger = logger;

private readonly ILogger<NewsService> _logger = loggerFactory.CreateLogger<NewsService>();

public async Task<string> GetTopStoryAsJson()
{
Expand Down

0 comments on commit 5e458d1

Please sign in to comment.