-
Notifications
You must be signed in to change notification settings - Fork 19
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
Issue logging with Configuration created from code with version 1.0.0 (works in 0.1.32.1) #6
Comments
Hi, The issue is version Two options:
[assembly: AliasRepository("slf4net-repository")]
static void Main(string[] args)
{
// Create log4net ILoggerFactory and set the resolver
var factory = new slf4net.log4net.Log4netLoggerFactory();
var resolver = new SimpleFactoryResolver(factory);
slf4net.LoggerFactory.SetFactoryResolver(resolver);
var log = slf4net.LoggerFactory.GetLogger(typeof(Program));
var layout = new PatternLayout
{
ConversionPattern = "%d{ABSOLUTE}: %message %newline"
};
layout.ActivateOptions();
var fileAppender = new RollingFileAppender();
fileAppender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date;
fileAppender.Layout = layout;
var path = GetLoggingPath();
fileAppender.File = path + System.IO.Path.DirectorySeparatorChar + "LISlogging_.txt";
fileAppender.AppendToFile = true;
fileAppender.PreserveLogFileNameExtension = true;
fileAppender.StaticLogFileName = false;
fileAppender.DatePattern = "yyyy-MM-dd";
fileAppender.MaxSizeRollBackups = 10;
fileAppender.ActivateOptions();
ILoggerRepository repository = log4net.LogManager.GetRepository(slf4net.log4net.Log4netLoggerFactory.SLF4NET_REPOSITORY);
BasicConfigurator.Configure(repository, fileAppender);
var root = (repository as Hierarchy)?.Root;
if (root == null) return;
root.Level = log4net.Core.Level.All;
// trigger logging
log.Info("log this line");
}
} Honestly, we weren't really expecting this usage pattern so it could be better. Being able to set/confgure the repository name used by slf4net and to also check first if it already exists could be useful enhancements. |
Hi Thanks for the answer. |
LoggingIssue.zip
The attached dummy project shows an issue with slf4net.log4net v1.0.0 nuget package. Running this code with version 0.1.32.1 works fine. The file is created and the logged line is there. When upgrading to version 1.0.0 and deleting the file (../ProgramData/LoggingTesting/LisLogging_{Date}.txt) and then running it again. The log file is created, but the logged line is not present anymore.
The text was updated successfully, but these errors were encountered: