Configure Microsoft.Owin.Logging.ILogger

How to set mine ILoggerto record to another place? I would like to write my magazines in C:\Logs\MyLogFile.log.

I configure my custom LoggerFactorylike this:

app.Properties["server.LoggerFactory"] = new MyCustomLoggerFactory();

MyCustomLoggerFactory as follows:

public class MyCustomLoggerFactory: ILoggerFactory
{
    public ILogger Create(string name)
    {
        return new CustomLogger();
    }
}

Then the interface ICustomLoggerand class CustomLoggerlook like this:

public interface ICustomLogger : ILogger
{

}

public class CustomLogger : ICustomLogger 
{
    public bool WriteCore(TraceEventType eventType, int eventId, object state, 
        Exception exception, Func<object, Exception, string> formatter)
    {
        throw new NotImplementedException("Dont use this one dummy");
    }
}

Can't install LogLevel or Url where the log file is written? Ideally, I would also like to use log4net for this.

+4
source share
1 answer

You can make a log4net implementation for your user registrar, you should use TraceEventType to determine the level of logging:

public class CustomLogger : ICustomLogger 
{
    public bool WriteCore(TraceEventType eventType, int eventId, object state, 
        Exception exception, Func<object, Exception, string> formatter)
    {
        ILog logger = LogManager.GetLogger("myowinlogger");
        switch (eventType){
            case(TraceEventType.Critical): 
            {
                logger.Fatal(...);
            }
            ....

    }
}

, , log4net .

+3

All Articles