Last active
January 18, 2024 05:58
-
-
Save karenpayneoregon/f4ddadfef51462dc86e26361e71ef996 to your computer and use it in GitHub Desktop.
Get all pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Microsoft.AspNetCore.Mvc.RazorPages | |
@using Microsoft.AspNetCore.Routing | |
public class IndexModel : PageModel | |
{ | |
private readonly IEnumerable<EndpointDataSource> _endpointSources; | |
public IEnumerable<RouteEndpoint> EndpointSources { get; set; } | |
public IndexModel(IEnumerable<EndpointDataSource> endpointSources) | |
{ | |
_endpointSources = endpointSources; | |
EndpointSources = _endpointSources | |
.SelectMany(x => x.Endpoints) | |
.OfType<RouteEndpoint>(); | |
} | |
public void OnGet() | |
{ | |
foreach (RouteEndpoint rep in EndpointSources) | |
{ | |
Log.Information("{P1} {P2}", rep.RoutePattern.RawText, rep.DisplayName); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var builder = WebApplication.CreateBuilder(args); | |
SetupLogging.Development(); | |
builder.Services.AddRazorPages(op => | |
{ | |
op.Conventions.AddFolderRouteModelConvention("/", model => | |
{ | |
foreach (var selector in model.Selectors) | |
{ | |
var pageName = selector.AttributeRouteModel.Template.ToString(); | |
Log.Information("'{P1}'", pageName); | |
} | |
}); | |
}); | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Serilog; | |
using SeriLogLibrary; | |
using static System.DateTime; | |
namespace WebApplication1.Classes; | |
public class SetupLogging | |
{ | |
public static void Development() | |
{ | |
Log.Logger = new LoggerConfiguration() | |
.MinimumLevel.Verbose() | |
.WriteTo.Console(theme: SeriLogCustomThemes.Theme3()) | |
.WriteTo.File(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LogFiles", $"{Now.Year}-{Now.Month}-{Now.Day}", "Log.txt"), | |
rollingInterval: RollingInterval.Infinite, | |
outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level}] {Message}{NewLine}{Exception}") | |
.CreateLogger(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment