nestjs-seq
🐷 Seq logging module for Nest framework (node.js)

Installation
# Using npm
$ npm i --save @jasonsoft/nestjs-seq
# Using yarn
$ yarn add @jasonsoft/nestjs-seq
# Using pnpm
$ pnpm add @jasonsoft/nestjs-seq
Quick Start
After successfully installing the package, proceed to integrate the SeqLoggerModule into your project’s root AppModule.
Static Configuration
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SeqLoggerModule } from '@jasonsoft/nestjs-seq';
@Module({
imports: [
SeqLoggerModule.forRoot({
serverUrl: 'http://localhost:5341',
apiKey: 'K7iUhZ9OSp6oX5EOCfPt',
extendMetaProperties: {
serviceName: 'product-service',
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Async Configuration
import { ConfigModule, ConfigService } from '@nestjs/config';
import { SeqLoggerModule } from '@jasonsoft/nestjs-seq';
@Module({
imports: [
ConfigModule.forRoot(),
SeqLoggerModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
serverUrl: configService.get('SEQ_SERVER_URL'),
apiKey: configService.get('SEQ_API_KEY'),
extendMetaProperties: {
serviceName: configService.get('SEQ_SERVICE_NAME'),
},
}),
inject: [ConfigService],
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
✨ Seq Logger Options Documentation
Please refer to the Seq Logger Options Documentation for detailed explanations of the configuration options available for the Seq Logger. For immediate access to the document, click here.
Usage
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { SeqLogger } from '@jasonsoft/nestjs-seq';
@Controller()
export class AppController {
constructor(
private readonly logger: SeqLogger,
private readonly appService: AppService,
) {}
@Get()
getHello(): string {
this.logger.info('getHello - start', AppController.name);
const result = this.appService.getHello();
this.logger.debug(
`Retrieving result from {name}`,
{
name: 'AppService',
result,
note: 'The message template function is used here',
},
AppController.name,
);
try {
throw new Error('Oops! Something whimsically wrong just happened!');
} catch (error: any) {
this.logger.error(error, AppController.name);
this.logger.error(
'The error has been successfully captured and handled!',
error,
AppController.name,
);
return result;
}
}
}
Seq
Seq is a powerful centralized logging system. Explore the logs we have gathered:

Nest System Console Logging to Seq
This section describes how to integrate Nest system console logging with Seq through a custom console logger. To set up this integration, follow the steps below:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
/**
* Import the ConsoleSeqLogger to extend the built-in logger for supporting Seq.
* Added by Jason.Song (成长的小猪) on 2021/09/24
*/
import { ConsoleSeqLogger } from '@jasonsoft/nestjs-seq';
async function bootstrap() {
/**
* Set bufferLogs to true to buffer all logs until the ConsoleSeqLogger is attached.
* This ensures that logs are captured during the application initialization.
* If initialization fails, Nest will use the default ConsoleLogger to output error messages.
*/
const app = await NestFactory.create(AppModule, {
bufferLogs: true,
});
/**
* Use the ConsoleSeqLogger to extend the built-in logger functionality.
*/
app.useLogger(app.get(ConsoleSeqLogger));
await app.listen(3000);
}
bootstrap();
This setup allows your NestJS application to log directly to Seq, providing a centralized logging solution.
Seq Interface Overview showing the integration of Nest System Console Logging with Seq.

Example Repository
For a practical implementation example, visit the nestjs-seq-example repository on GitHub.
评论