10 changed files with 260 additions and 92 deletions
-
51src/Shentun.Sms.Application/Jobs/SmsSendJob.cs
-
64src/Shentun.Sms.Application/Jobs/SmsTaskJob.cs
-
10src/Shentun.Sms.EntityFrameworkCore/EntityFrameworkCore/SmsDbContext.cs
-
52src/Shentun.Sms.HttpApi.Host/Logger/CustomLogger.cs
-
39src/Shentun.Sms.HttpApi.Host/Program.cs
-
30src/Shentun.Sms.HttpApi.Host/SmsHttpApiHostModule.cs
-
6src/Shentun.Sms.HttpApi.Host/appsettings.json
-
1src/Shentun.Sms.Service/Shentun.Sms.Service.csproj
-
10src/Shentun.Sms.Service/Sms/SmsFactory.cs
-
11src/Shentun.Sms.Service/Sms/TencentSms.cs
@ -0,0 +1,52 @@ |
|||
using Microsoft.Extensions.Logging; |
|||
using System; |
|||
using System.IO; |
|||
|
|||
namespace Shentun.Sms.Logger |
|||
{ |
|||
public class CustomLogger : ILogger |
|||
{ |
|||
private string _categoryName; |
|||
|
|||
public CustomLogger(string categoryName) |
|||
{ |
|||
_categoryName = categoryName; |
|||
} |
|||
|
|||
|
|||
|
|||
public IDisposable BeginScope<TState>(TState state) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
public bool IsEnabled(LogLevel logLevel) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) |
|||
{ |
|||
string message = $"{DateTime.Now} - {logLevel} - {_categoryName} - {formatter(state, exception)}"; |
|||
File.AppendAllText("job_log.txt", message); |
|||
} |
|||
|
|||
//public static void LogInformation(this ILogger logger, string? message, params object?[] args)
|
|||
//{
|
|||
// logger.Log(LogLevel.Information, message, args);
|
|||
//}
|
|||
|
|||
} |
|||
|
|||
public class CustomLoggerProvider : ILoggerProvider |
|||
{ |
|||
public ILogger CreateLogger(string categoryName) |
|||
{ |
|||
return new CustomLogger(categoryName); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue