Skip to content

overtly/core-logging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logging

项目层次说明

Overt.Core.Logging v1.0.2

1. 项目目录

|-dllconfigs                                    配置文件保存
|
|-Exless                                        Exceptionless
|-|-ExlessLogger.cs                        	实现ILogger
|-|-ExlessLoggerProvider.cs                     实现ILoggerProvider
|
|-NLog                                    	NLog
|-|-NLogOptions.cs                       	NLog配置注入类
|
|-ServiceCollectionExtensions.cs            	netcore注入

2. 版本及支持

  • Nuget版本:V 1.0.2
  • 框架支持: netcoreapp2.2

3. 项目依赖

  • netcoreapp2.2
NLog.Extensions.Logging 1.2.1
System.Data.SqlClient 4.4.0
    
Exceptionless.AspNetCore 4.3.2012
Microsoft.Extensions.DependencyInjection 2.2.0
Microsoft.Extensions.Logging 2.2.0

使用

1. Nuget包引用

Install-Package Overt.Core.Logging -Version 1.0.2

2. 使用

(1)NLog
  • 添加配置文件 /dllconfigs/Overt.Core.Logging.dll.config
  • 代码中使用
// ConsoleApplication
 var host = new HostBuilder()
     .ConfigureLogging(ConfigureLogging)    //注入日志组件
     .ConfigureServices(ConfigureServices)  //提供通用注入配置
     .Build();
host.Run();



/// <summary>
/// 添加ILoggerProvider
/// </summary>
/// <param name="context"></param>
/// <param name="loggingBuilder"></param>
private static void ConfigureLogging(HostBuilderContext context, ILoggingBuilder loggingBuilder)
{
    loggingBuilder.AddConfiguration(context.Configuration.GetSection("Logging"));
    loggingBuilder.AddNLogLogging();
}

// WebApplication
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddNLogLogging();
}

(2)Exceptionless
  • 配置文件中添加Exceptionless节点
"Exceptionless": {
  "ServerUrl": "exless服务地址",
  "ApiKey": "项目apikey"
  "Tags": "自定义标签"
}
  • 代码中使用
// ConsoleApplication
var host = new HostBuilder()
    .Build();
host.Services.AddExlessLogging();
host.Run();



// WebApplication
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
	app.AddExlessLogging();
}