示例#1
0
        internal static string ToSerializedValue(this TraceLogLevel value)
        {
            switch (value)
            {
            case TraceLogLevel.Error:
                return("Error");

            case TraceLogLevel.Information:
                return("Information");

            case TraceLogLevel.Debug:
                return("Debug");

            case TraceLogLevel.Verbose:
                return("Verbose");
            }
            return(null);
        }
        public static LoggingConfiguration Create(string connectionString, TraceLogLevel traceLogLevel)
        {
            var config = new LoggingConfiguration();

            var databaseTarget = new DatabaseTarget();

            config.AddTarget("database", databaseTarget);

            databaseTarget.ConnectionString = connectionString;
            databaseTarget.CommandText      = @"
INSERT INTO [dbo].[TraceLogs] (
    [Logger],
    [Level],
    [ThreadId],
    [MachineName],
    [Message]
) VALUES (
    @Logger,
    @Level,
    @ThreadId,
    @MachineName,
    @Message
);
";
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@Logger", new SimpleLayout("${logger}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@Level", new SimpleLayout("${uppercase:${level}}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@ThreadId", new SimpleLayout("${threadid}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@MachineName", new SimpleLayout("${machinename}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@CallSite", new SimpleLayout("${callsite}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@UserName", new SimpleLayout("${identity}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@Message", new SimpleLayout("${message}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@StackTrace", new SimpleLayout("${exception:format=tostring}")));

            var loggingRule = new LoggingRule("*", traceLogLevel.ToNLogLevel(), databaseTarget);

            config.LoggingRules.Add(loggingRule);

            return(config);
        }
示例#3
0
        public static LogLevel ToNLogLevel(this TraceLogLevel traceLogLevel)
        {
            if (traceLogLevel == null)
            {
                return(LogLevel.Off);
            }

            if (traceLogLevel.Equals(TraceLogLevel.Trace))
            {
                return(LogLevel.Trace);
            }
            if (traceLogLevel.Equals(TraceLogLevel.Info))
            {
                return(LogLevel.Info);
            }
            if (traceLogLevel.Equals(TraceLogLevel.Error))
            {
                return(LogLevel.Error);
            }

            return(LogLevel.Off);
        }
        public static LoggingConfiguration Create(string connectionString, TraceLogLevel traceLogLevel)
        {
            var config = new LoggingConfiguration();

            var databaseTarget = new DatabaseTarget();
            config.AddTarget("database", databaseTarget);

            databaseTarget.ConnectionString = connectionString;
            databaseTarget.CommandText = @"
INSERT INTO [dbo].[TraceLogs] (
    [Logger],
    [Level],
    [ThreadId],
    [MachineName],
    [Message]
) VALUES (
    @Logger,
    @Level,
    @ThreadId,
    @MachineName,
    @Message
);
";
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@Logger", new SimpleLayout("${logger}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@Level", new SimpleLayout("${uppercase:${level}}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@ThreadId", new SimpleLayout("${threadid}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@MachineName", new SimpleLayout("${machinename}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@CallSite", new SimpleLayout("${callsite}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@UserName", new SimpleLayout("${identity}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@Message", new SimpleLayout("${message}")));
            databaseTarget.Parameters.Add(new DatabaseParameterInfo("@StackTrace", new SimpleLayout("${exception:format=tostring}")));

            var loggingRule = new LoggingRule("*", traceLogLevel.ToNLogLevel(), databaseTarget);
            config.LoggingRules.Add(loggingRule);

            return config;
        }
示例#5
0
 /// <summary>Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR)</summary>
 public static void TraceLog(TraceLogLevel logLevel, string text)
 {
     using var str1 = text.ToUTF8Buffer();
     TraceLog(logLevel, str1.AsPointer());
 }
 public static void Initialize(string connectionString, TraceLogLevel traceLogLevel)
 {
     var config = TraceLogConfigurationFactory.Create(connectionString, traceLogLevel);
     NLog.LogManager.Configuration = config;
 }