-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,550 additions
and
1,629 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
examples/Logary.AspNetCore.API/Controllers/TodoController.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Logary.AspNetCore.API.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Logary.AspNetCore.API.Controllers | ||
{ | ||
[Route("api/todo")] | ||
[ApiController] | ||
public class TodoController : ControllerBase | ||
{ | ||
readonly TodoContext _context; | ||
|
||
public TodoController(TodoContext context) | ||
{ | ||
_context = context; | ||
|
||
if (_context.TodoItems.Any()) return; | ||
|
||
// Create a new TodoItem if collection is empty, | ||
// which means you can't delete all TodoItems. | ||
_context.TodoItems.Add(new TodoItem { Name = "Use Logary for logging" }); | ||
_context.TodoItems.Add(new TodoItem { Name = "Use Logary for Prometheus scraping" }); | ||
_context.TodoItems.Add(new TodoItem { Name = "Use Logary for Jaeger tracing" }); | ||
_context.TodoItems.Add(new TodoItem { Name = "Use Logary for rate limiting with Logary.Trace.Samplers.RateLimiter" }); | ||
_context.SaveChanges(); | ||
} | ||
|
||
// GET: api/todo | ||
[HttpGet] | ||
public async Task<ActionResult<IEnumerable<TodoItem>>> GetTodoItems() | ||
{ | ||
return await _context.TodoItems.ToListAsync(); | ||
} | ||
|
||
// GET: api/todo/5 | ||
[HttpGet("{id}")] | ||
public async Task<ActionResult<TodoItem>> GetTodoItem(long id) | ||
{ | ||
var todoItem = await _context.TodoItems.FindAsync(id); | ||
|
||
if (todoItem == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return todoItem; | ||
} | ||
|
||
// POST: api/todo | ||
[HttpPost] | ||
public async Task<ActionResult<TodoItem>> PostTodoItem(TodoItem item) | ||
{ | ||
_context.TodoItems.Add(item); | ||
await _context.SaveChangesAsync(); | ||
|
||
return CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item); | ||
} | ||
|
||
// PUT: api/todo/5 | ||
[HttpPut("{id}")] | ||
public async Task<IActionResult> PutTodoItem(long id, TodoItem item) | ||
{ | ||
if (id != item.Id) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
_context.Entry(item).State = EntityState.Modified; | ||
await _context.SaveChangesAsync(); | ||
|
||
return NoContent(); | ||
} | ||
|
||
// DELETE: api/todo/5 | ||
[HttpDelete("{id}")] | ||
public async Task<IActionResult> DeleteTodoItem(long id) | ||
{ | ||
var todoItem = await _context.TodoItems.FindAsync(id); | ||
|
||
if (todoItem == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
_context.TodoItems.Remove(todoItem); | ||
await _context.SaveChangesAsync(); | ||
|
||
return NoContent(); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/Logary.AspNetCore.API/Logary.AspNetCore.API.csproj
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\adapters\Logary.Adapters.AspNetCore\Logary.Adapters.AspNetCore.fsproj"/> | ||
<ProjectReference Include="..\..\src\Logary.CSharp\Logary.CSharp.csproj"/> | ||
<ProjectReference Include="..\..\src\Logary\Logary.fsproj"/> | ||
<ProjectReference Include="..\..\src\targets\Logary.Targets.Jaeger\Logary.Targets.Jaeger.fsproj"/> | ||
</ItemGroup> | ||
|
||
<Import Project="..\..\.paket\Paket.Restore.targets"/> | ||
</Project> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Logary.AspNetCore.API.Models | ||
{ | ||
public class TodoContext : DbContext | ||
{ | ||
public TodoContext(DbContextOptions<TodoContext> options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<TodoItem> TodoItems { get; set; } | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Logary.AspNetCore.API.Models | ||
{ | ||
public class TodoItem | ||
{ | ||
public long Id { get; set; } | ||
public string Name { get; set; } | ||
public bool IsComplete { get; set; } | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Threading.Tasks; | ||
using Logary.Configuration; | ||
using Logary.Targets; | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using ILogger = Logary.Configuration.ILogger; | ||
|
||
namespace Logary.AspNetCore.API | ||
{ | ||
public class Program | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
var logary = await LogaryFactory.New("Logary.AspNetCore.API", config => | ||
config | ||
.InternalLogger(ILogger.NewLiterateConsole(LogLevel.Verbose)) | ||
.LoggerMinLevel(".*", LogLevel.Verbose) | ||
.Target<LiterateConsole.Builder>( | ||
"literate", | ||
lit => lit.Target.WithExtendedTokeniser().Done()) | ||
.Target<Logary.Targets.Jaeger.Builder>( | ||
"jaeger", | ||
x => | ||
x.Target | ||
.WithJaegerAgent("localhost", 30831) | ||
.Done()) | ||
); | ||
|
||
CreateWebHostBuilder(args, logary).Build().Run(); | ||
} | ||
|
||
static IWebHostBuilder CreateWebHostBuilder(string[] args, LogManager logary) | ||
{ | ||
return WebHost.CreateDefaultBuilder(args) | ||
.ConfigureLogging(logging => logging.AddLogary(logary)) | ||
.UseStartup<Startup>(); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
examples/Logary.AspNetCore.API/Properties/launchSettings.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:5779", | ||
"sslPort": 44307 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "api/values", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"Logary.AspNetCore.API": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "api/todo", | ||
"applicationUrl": "https://localhost:5001;http://localhost:5000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Logary.AspNetCore.API.Models; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Logary.AspNetCore.API | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddDbContext<TodoContext>(opt => | ||
opt.UseInMemoryDatabase("TodoList")); | ||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
app.UseDeveloperExceptionPage(); | ||
else | ||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | ||
app.UseHsts(); | ||
|
||
//app.UseHttpsRedirection(); | ||
app.UseMvc(); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
group AspNetCoreExample | ||
Microsoft.AspNetCore.App | ||
Microsoft.AspNetCore |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
group AspNetCoreAdapterExample | ||
group AspNetCoreExample | ||
Microsoft.AspNetCore.App |
Oops, something went wrong.