-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1465 remove warning #809
1465 remove warning #809
Changes from 13 commits
70a36b1
4a8788f
808b0ac
3149809
904957a
f477ec8
be2dc35
6cddfb8
bf2083b
b9eb7ac
f699869
588318b
6f34ffd
a3c7a07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace OSPSuite.Core.Extensions | ||
{ | ||
public static class FunctionExtensions | ||
{ | ||
public static T Compose<T>(this Func<T, T> f1, Func<T, T> f2, T value) | ||
{ | ||
return f2.Invoke(f1.Invoke(value)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace OSPSuite.Core.Services | ||
{ | ||
public interface ILoggerCreator | ||
{ | ||
ILogger GetOrCreateLogger(string categoryName); | ||
|
||
ILoggerCreator AddLoggingBuilderConfiguration(Func<ILoggingBuilder, ILoggingBuilder> configuration); | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Microsoft.Extensions.Logging; | ||
using OSPSuite.Core.Extensions; | ||
using OSPSuite.Core.Services; | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace OSPSuite.Infrastructure.Services | ||
{ | ||
public class LoggerCreator : ILoggerCreator | ||
{ | ||
private readonly ConcurrentDictionary<string, ILogger> _loggerDict = new ConcurrentDictionary<string, ILogger>(); | ||
private List<Func<ILoggingBuilder, ILoggingBuilder>> _loggingBuilderConfigurations = new List<Func<ILoggingBuilder, ILoggingBuilder>>() { builder => builder }; | ||
|
||
public ILoggerCreator AddLoggingBuilderConfiguration(Func<ILoggingBuilder, ILoggingBuilder> configuration) | ||
{ | ||
_loggingBuilderConfigurations.Add(configuration); | ||
return this; | ||
} | ||
|
||
public ILogger GetOrCreateLogger(string categoryName) | ||
{ | ||
var logger = _loggerDict.GetOrAdd(categoryName, (_) => SetupLogger(categoryName)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small improvement. Return directly instead of creating a variable |
||
return logger; | ||
} | ||
|
||
private ILogger SetupLogger(string categoryName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not follow our convention. Private method => camelCase => |
||
{ | ||
ILogger logger; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small improvement. |
||
|
||
using (var loggerFactory = LoggerFactory.Create( | ||
builder => | ||
_loggingBuilderConfigurations.Aggregate( | ||
(f1, f2) => config => f1.Compose(f2, config) | ||
).Invoke(builder) | ||
)) | ||
{ | ||
logger = loggerFactory.CreateLogger(categoryName); | ||
}; | ||
return logger; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
| ||
using Microsoft.Extensions.Logging; | ||
using Serilog; | ||
|
||
namespace OSPSuite.Infrastructure.Services | ||
{ | ||
public static class LoggingBuilderExtensions | ||
{ | ||
public static ILoggingBuilder AddFile(this ILoggingBuilder builder, string logFileFullPath) | ||
{ | ||
builder.AddSerilog( | ||
new LoggerConfiguration() | ||
.WriteTo.File(logFileFullPath) | ||
.CreateLogger() | ||
); | ||
return builder; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. Well done