• logback配置数据源日志error级别写入库


    LOGBACK.XML中配置

    <appender name="db_log" class="ch.qos.logback.classic.db.DBAppender">
            <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
                <driverClass>${logback.dblog.dirver}</driverClass>
                <url>jdbc:mysql://${logback.dblog.serverName}:${logback.dblog.port}/${logback.dblog.databaseName}?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC</url>
                <user>${logback.dblog.user}</user>
                <password>${logback.dblog.password}</password>
            </connectionSource>
    </appender>
    <root level="error">
            <appender-ref ref="console"/>
            <appender-ref ref="db_log" />  
    </root>
    <logger name="dbLogger" level="error" additivity="false">
            <appender-ref ref="db_log"/>
    </logger>

    资源文件配置:

    # LOGBACK
    logback.dblog.dirver=${logback.dblog.dirver}
    logback.dblog.serverName=${logback.dblog.serverName}
    logback.dblog.port=${logback.dblog.port}
    logback.dblog.databaseName=${logback.dblog.databaseName}
    logback.dblog.user=${logback.dblog.user}
    logback.dblog.password=${logback.dblog.password}

    另外如果要日志写库需要在自己的库里建立三张表:

    BEGIN;
    DROP TABLE IF EXISTS logging_event_property;
    DROP TABLE IF EXISTS logging_event_exception;
    DROP TABLE IF EXISTS logging_event;
    COMMIT;
    
    BEGIN;
    CREATE TABLE logging_event 
      (
        timestmp         BIGINT NOT NULL,
        formatted_message  TEXT NOT NULL,
        logger_name       VARCHAR(254) NOT NULL,
        level_string      VARCHAR(254) NOT NULL,
        thread_name       VARCHAR(254),
        reference_flag    SMALLINT,
        arg0              VARCHAR(254),
        arg1              VARCHAR(254),
        arg2              VARCHAR(254),
        arg3              VARCHAR(254),
        caller_filename   VARCHAR(254) NOT NULL,
        caller_class      VARCHAR(254) NOT NULL,
        caller_method     VARCHAR(254) NOT NULL,
        caller_line       CHAR(4) NOT NULL,
        event_id          BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
      );
    COMMIT;
    
    
    BEGIN;
    CREATE TABLE logging_event_property
      (
        event_id       BIGINT NOT NULL,
        mapped_key        VARCHAR(254) NOT NULL,
        mapped_value      TEXT,
        PRIMARY KEY(event_id, mapped_key),
        FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
      );
    COMMIT;
    
    
    BEGIN;
    CREATE TABLE logging_event_exception
      (
        event_id         BIGINT NOT NULL,
        i                SMALLINT NOT NULL,
        trace_line       VARCHAR(254) NOT NULL,
        PRIMARY KEY(event_id, i),
        FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
      );
    COMMIT;
  • 相关阅读:
    C#获取MD5哈希字符串
    C#序列化和反序列化Json数据
    C# Http请求
    C#DAL数据访问层
    C# ThreadPool.QueueUserWorkItem()之线程池异步
    C#以文件夹共享方式实现2G以上大文件传输
    该进程不具有执行此操作所需的“SeSecurityPrivilege”特权
    IIS绑定网站用域名进行访问的过程
    js获取url指定参数值
    js闭包(for循环内给元素添加事件)
  • 原文地址:https://www.cnblogs.com/ixixi/p/11676165.html
Copyright © 2020-2023  润新知