public ILogger CreateLogger(string categoryName)
        {
            var syncLogger = new SyncLogger();

            if (this.ConfigureOptions != null)
            {
                this.ConfigureOptions.Configure(syncOptions);
            }

            // Override MinLevel, if coming from typed Sync Options
            if (this.ConfigureSyncOptions != null)
            {
                this.ConfigureSyncOptions.Configure(syncOptions);
            }

            if (syncOptions != null)
            {
                syncLogger.MinimumLevel = syncOptions.MinLevel;

                if (syncOptions.outputWriters != null && syncOptions.outputWriters.Count > 0)
                {
                    syncLogger.outputWriters = syncOptions.outputWriters;
                }
                else
                {
                    syncLogger.AddDebug();
                }
            }

            return(syncLogger);
        }
Ejemplo n.º 2
0
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void Log(this ILogger logger, LogLevel logLevel, SyncStage stage, string message, params object[] args)
        //        => logger.Log(logLevel, new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void Log(this ILogger logger, LogLevel logLevel, SyncStage stage, Exception exception, string message, params object[] args)
        //        => logger.Log(logLevel, new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), exception, message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogTrace(this ILogger logger, SyncStage stage, string message, params object[] args)
        //         => logger.LogTrace(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogTrace(this ILogger logger, SyncStage stage, Exception exception, string message, params object[] args)
        //        => logger.LogTrace(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), exception, message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogCritical(this ILogger logger, SyncStage stage, string message, params object[] args)
        //        => logger.LogCritical(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogCritical(this ILogger logger, SyncStage stage, Exception exception, string message, params object[] args)
        //        => logger.LogCritical(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), exception, message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogDebug(this ILogger logger, SyncStage stage, string message, params object[] args)
        //       => logger.LogDebug(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogDebug(this ILogger logger, SyncStage stage, Exception exception, string message, params object[] args)
        //        => logger.LogDebug(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), exception, message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogError(this ILogger logger, SyncStage stage, string message, params object[] args)
        //      => logger.LogError(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogError(this ILogger logger, SyncStage stage, Exception exception, string message, params object[] args)
        //        => logger.LogError(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), exception, message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogInformation(this ILogger logger, SyncStage stage, string message, params object[] args)
        //      => logger.LogInformation(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogInformation(this ILogger logger, SyncStage stage, Exception exception, string message, params object[] args)
        //        => logger.LogInformation(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), exception, message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogWarning(this ILogger logger, SyncStage stage, string message, params object[] args)
        //       => logger.LogWarning(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), message, args);
        //    /// <summary>
        //    /// Create a Log with an EventId generated from a SyncStage enumeration
        //    /// </summary>
        //    public static void LogWarning(this ILogger logger, SyncStage stage, Exception exception, string message, params object[] args)
        //        => logger.LogWarning(new EventId((int)stage, Enum.GetName(typeof(SyncStage), stage)), exception, message, args);


        public static void LogTrace <T>(this ILogger logger, EventId id, T value) where T : class
        {
            if (!logger.IsEnabled(LogLevel.Trace))
            {
                return;
            }

            if (value is string)
            {
                logger.LogTrace(id, value as string, null);
                return;
            }

            var log = SyncLogger.GetLogMessageFrom(value, id);

            logger.LogTrace(id, log.Message, log.Args);
        }