Skip to content

Commit

Permalink
add log to demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesying authored and jamesying committed Oct 23, 2017
1 parent bda90e0 commit ad77671
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
6 changes: 0 additions & 6 deletions JCWeichatCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DemoWeb", "demo\DemoWeb\Dem
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PassivityRequestMessageDemo", "demo\PassivityRequestMessageDemo\PassivityRequestMessageDemo.csproj", "{A2A84AE2-E949-43F9-B41D-CE7BFBC4F7B3}"
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{FA395820-6621-4353-8388-D1DD99A4D5DC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -47,10 +45,6 @@ Global
{A2A84AE2-E949-43F9-B41D-CE7BFBC4F7B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2A84AE2-E949-43F9-B41D-CE7BFBC4F7B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2A84AE2-E949-43F9-B41D-CE7BFBC4F7B3}.Release|Any CPU.Build.0 = Release|Any CPU
{FA395820-6621-4353-8388-D1DD99A4D5DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA395820-6621-4353-8388-D1DD99A4D5DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA395820-6621-4353-8388-D1DD99A4D5DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA395820-6621-4353-8388-D1DD99A4D5DC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using JCSoft.WX.Framework.Models.Requests;
using JCSoft.WX.Framework.Models.Responses;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -15,9 +17,11 @@ namespace PassivityRequestMessageDemo.Controllers
public class WxMessageController : Controller
{
private WXOptions wXOptions;
public WxMessageController(IOptions<WXOptions> options)
private ILogger<WxMessageController> _logger;
public WxMessageController(IOptions<WXOptions> options, ILoggerFactory loggerFactory)
{
wXOptions = options.Value;
_logger = loggerFactory.CreateLogger<WxMessageController>();
}

[HttpGet]
Expand All @@ -30,13 +34,19 @@ public JsonResult Get()
public ResponseMessage Post([FromBody]RequestMessage request)
{
var textRequest = request as RequestTextMessage;
return new ResponseTextMessage
var response = new ResponseTextMessage
{
FromUserName = "jamesying",
ToUserName = "candy",
Content = textRequest?.Content ?? "this is a test!",
CreateTime = DateTime.Now.Ticks,
};

_logger.LogInformation("[Recive a Message]\r\n request is :{0} \r\n response:{1}",
JsonConvert.SerializeObject(request),
JsonConvert.SerializeObject(response));

return response;
}

[HttpPut]
Expand Down
5 changes: 4 additions & 1 deletion demo/PassivityRequestMessageDemo/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand Down
2 changes: 1 addition & 1 deletion demo/PassivityRequestMessageDemo/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
"Default": "Information"
}
},
"Console": {
Expand Down

0 comments on commit ad77671

Please sign in to comment.