Added serilog to the application.

pull/81/head
Halil İbrahim Kalkan 9 years ago
parent 0c46ae922c
commit f83310a552

@ -6,7 +6,10 @@ services:
image: tutum/mongodb
environment:
- AUTH=no
ports:
- "27017:27017"
- "28017:28017"
abpidentity_httpapihost:
image: abpidentity/httpapihost
environment:

@ -1,6 +1,7 @@
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Domain.Repositories;
@ -46,11 +47,16 @@ namespace AbpDesk.Blogging
{
using (var scope = context.ServiceProvider.CreateScope())
{
var logger = context.ServiceProvider.GetRequiredService<ILogger<AbpDeskMongoBlogModule>>();
logger.LogInformation("Running seed data for mongo blog module...");
using (var uow = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>().Begin())
{
var blogPostRepository = scope.ServiceProvider.GetRequiredService<IQueryableRepository<BlogPost>>();
if (blogPostRepository.Any())
{
logger.LogInformation($"No need to seed database since there are already {blogPostRepository.Count()} blog posts!");
return;
}
@ -79,7 +85,11 @@ namespace AbpDesk.Blogging
}
);
logger.LogInformation("Inserted two blog post. completing the unit of work...");
uow.Complete();
logger.LogInformation("Completed!");
}
}
}

@ -2,7 +2,7 @@
<h2>Blog Posts</h2>
<ul>
<ul class="blog-post-list">
@foreach (var post in Model)
{
<h3>@post.Title</h3>
@ -13,11 +13,10 @@
}
else
{
<h4>Comments</h4>
<h5>Comments</h5>
foreach (var comment in post.Comments)
{
<h5>@comment.Name</h5>
<p>@comment.Message</p>
<p><strong>@comment.Name</strong>: @comment.Message</p>
}
}
}

@ -21,6 +21,6 @@
},
"scripts": {
"postcompile": [ "xcopy %compile:OutputDir%\\AbpDesk.MongoBlog.dll ..\\Web_PlugIns" ]
"postcompile": [ "xcopy /y %compile:OutputDir%\\AbpDesk.MongoBlog.dll ..\\Web_PlugIns\\" ]
}
}

@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Volo.Abp;
using Volo.Abp.AspNetCore.EmbeddedFiles;
using Volo.Abp.AspNetCore.Modularity;
@ -41,6 +40,7 @@ namespace AbpDesk.Web.Mvc
services.Configure<AbpIdentityHttpApiClientOptions>(configuration.GetSection("AbpIdentity:HttpApiClient"));
services.AddMvc();
services.AddAssemblyOf<AbpDeskWebMvcModule>();
}
@ -48,8 +48,6 @@ namespace AbpDesk.Web.Mvc
{
var app = context.GetApplicationBuilder();
context.GetLoggerFactory().AddConsole().AddDebug();
if (context.GetEnvironment().IsDevelopment())
{
app.UseDeveloperExceptionPage();

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Volo.Abp.Modularity.PlugIns;
namespace AbpDesk.Web.Mvc
@ -20,7 +21,7 @@ namespace AbpDesk.Web.Mvc
{
services.AddApplication<AbpDeskWebMvcModule>(options =>
{
/* @halil: I added Abp.MongoDb as a dependency to the main application.
/* @halil: I added Abp.MongoDb package as a dependency to the main application in order to use the blog plugin.
* Otherwise, we should add all dependencies (Recursively) into plugin folder
* and load in correct order. We should carefully think on that problem in the future.
*/
@ -34,6 +35,15 @@ namespace AbpDesk.Web.Mvc
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory
.AddConsole()
.AddDebug()
.AddSerilog(new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.RollingFile("logs.txt")
.CreateLogger()
);
app.InitializeApplication();
}
}

@ -28,7 +28,9 @@
"Volo.Abp.AspNetCore.EmbeddedFiles": "1.0.0-*",
"Volo.Abp.Identity.Web": "1.0.0-*",
"Volo.Abp.MongoDB": "1.0.0-*",
"Volo.Abp.Identity.HttpApi.Client": "1.0.0-*"
"Volo.Abp.Identity.HttpApi.Client": "1.0.0-*",
"Serilog.Extensions.Logging": "1.4.0",
"Serilog.Sinks.RollingFile": "3.3.0"
},
"tools": {

Loading…
Cancel
Save