forked from fanliang11/surging
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
5afb872
commit 8236ad9
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
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,35 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Serilog; | ||
using Serilog.Formatting.Elasticsearch; | ||
using Surging.Core.CPlatform; | ||
using Surging.Core.CPlatform.Module; | ||
using Surging.Core.ServiceHosting.Internal; | ||
|
||
namespace Surging.Core.Serilog | ||
{ | ||
public class SerilogModule: EnginePartModule | ||
{ | ||
public override void Initialize(AppModuleContext context) | ||
{ | ||
var serviceProvider = context.ServiceProvoider; | ||
base.Initialize(context); | ||
var section = AppConfig.GetSection("Serilog"); | ||
|
||
var logger = new LoggerConfiguration().ReadFrom.Configuration(section) | ||
//.WriteTo.RollingFile(new ElasticsearchJsonFormatter(renderMessageTemplate:false),"c:/logs/log-{Date}.log") | ||
//.WriteTo.Logger(config => { | ||
// config.Filter.ByIncludingOnly(evt=>evt.Level== Serilog.Events.LogEventLevel.Information).WriteTo.RollingFile() | ||
//}) | ||
.CreateLogger(); | ||
|
||
serviceProvider.GetInstances<ILoggerFactory>().AddSerilog(logger); | ||
serviceProvider.GetInstances<IApplicationLifetime>().ApplicationStopped.Register(Log.CloseAndFlush); | ||
} | ||
|
||
//public override void Dispose() | ||
//{ | ||
// //Log.CloseAndFlush(); | ||
// base.Dispose(); | ||
//} | ||
} | ||
} |
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,35 @@ | ||
//using Microsoft.Extensions.Logging; | ||
//using System; | ||
//using System.Collections.Concurrent; | ||
//using System.Collections.Generic; | ||
//using System.Text; | ||
//using Serilog; | ||
//using Serilog.Core; | ||
//using Microsoft.Extensions.Configuration; | ||
|
||
//namespace Surging.Core.Serilog | ||
//{ | ||
// public class SerilogProvider : ILoggerProvider | ||
// { | ||
// private readonly ConcurrentDictionary<string, Logger> _loggers = new ConcurrentDictionary<string, Logger>(); | ||
// private readonly IConfiguration _config; | ||
|
||
// public SerilogProvider(IConfiguration configuration) | ||
// { | ||
// _config = configuration; | ||
// } | ||
|
||
// public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName) | ||
// { | ||
// var log = new LoggerConfiguration() | ||
// .ReadFrom.Configuration(_config) | ||
// .CreateLogger(); | ||
// throw new NotImplementedException(); | ||
// } | ||
|
||
// public void Dispose() | ||
// { | ||
// _loggers.Clear(); | ||
// } | ||
// } | ||
//} |
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,23 @@ | ||
//using Microsoft.Extensions.Logging; | ||
//using System; | ||
|
||
//namespace Surging.Core.Serilog | ||
//{ | ||
// public class Serilogger : Microsoft.Extensions.Logging.ILogger | ||
// { | ||
// public IDisposable BeginScope<TState>(TState state) | ||
// { | ||
// throw new NotImplementedException(); | ||
// } | ||
|
||
// public bool IsEnabled(LogLevel logLevel) | ||
// { | ||
// throw new NotImplementedException(); | ||
// } | ||
|
||
// public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) | ||
// { | ||
// throw new NotImplementedException(); | ||
// } | ||
// } | ||
//} |
19 changes: 19 additions & 0 deletions
19
src/Surging.Core/Surging.Core.Serilog/Surging.Core.Serilog.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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Serilog" Version="2.9.0" /> | ||
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" /> | ||
<PackageReference Include="Serilog.Formatting.Elasticsearch" Version="8.0.1" /> | ||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" /> | ||
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Surging.Core.CPlatform\Surging.Core.CPlatform.csproj" /> | ||
</ItemGroup> | ||
|
||
</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
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