How i can show tracing of how my .net 8.0 console application which uses PnP core SDK interact with sharepoint #1399
Answered
by
jansenbe
mvcsharepointdev
asked this question in
Q&A
-
I have this .NET 8.0 console application, which uses PnP core SDK:-
but is there a way to show the requests that get executed from my console application? so i can track how the console application interact with SharePoint behind the senses ? Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
jansenbe
Feb 21, 2024
Replies: 1 comment 1 reply
-
@mvcsharepointdev : PnP Core supports .NET logging, so just configure logging in .NET. Below minimal console application sample has been configured to log debug events (see using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using PnP.Core.Auth;
using PnP.Core.Services;
string clientId = "<guid>";
string siteUrl = "https://bertonline.sharepoint.com/sites/prov-1";
// Creates and configures the host
var host = Host.CreateDefaultBuilder()
.ConfigureServices((context, services) =>
{
// Add PnP Core SDK
services.AddPnPCore(options =>
{
// Configure the interactive authentication provider as default
options.DefaultAuthenticationProvider = new InteractiveAuthenticationProvider()
{
ClientId = clientId,
RedirectUri = new Uri("http://localhost")
};
});
})
.ConfigureLogging((logger) =>
{
logger.SetMinimumLevel(LogLevel.Debug);
})
.UseConsoleLifetime()
.Build();
// Start the host
await host.StartAsync();
using (var scope = host.Services.CreateScope())
{
// Ask an IPnPContextFactory from the host
var pnpContextFactory = scope.ServiceProvider.GetRequiredService<IPnPContextFactory>();
// Create a PnPContext
using (var context = await pnpContextFactory.CreateAsync(new Uri(siteUrl)))
{
// Load the Title property of the site's root web
await context.Web.LoadAsync(p => p.Title);
Console.WriteLine($"The title of the web is {context.Web.Title}");
}
}
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mvcsharepointdev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mvcsharepointdev : PnP Core supports .NET logging, so just configure logging in .NET. Below minimal console application sample has been configured to log debug events (see
ConfigureLogging
method), which then shows the calls made API calls: