Skip to content

Incorrect use of the method "WriteLogEvent" (UsageWriteLogEvent)

Type Scope Severity Activated
by default
Minutes
to fix
Tags
Code smell BSL
OS
Info Yes 1 standard
badpractice

Description

It is important to specify the parameters correctly when writing to the Log event.

You can't hide exceptions. При обработке исключений нужно выполнять запись в журнал регистрации с подробным представлением ошибки. To do this, add to the event comment the result DetailErrorDescription(ErrorInfo())

Do not skip the 2nd parameter Log level. If you do not specify it, by default 1C will apply the Information error level, and this record may be lost in the stream of records.

The 5th parameter - a comment to the event of writing to the logging log - must not be omitted either.

Examples

Examples of Invalid Code

    WriteLogEvent("Event");// error
    WriteLogEvent("Event", EventLogLevel.Error);// error
    WriteLogEvent("Event", EventLogLevel.Error, , );// error
    WriteLogEvent("Event", , , , DetailErrorDescription(ErrorInfo()));

    WriteLogEvent("Event", EventLogLevel.Error, , , );// error

    Try
      ServerCode();
    Except
      WriteLogEvent("Event", EventLogLevel.Error, , ,
        ErrorDescription()); // error
      WriteLogEvent("Event", EventLogLevel.Error, , ,
        "Commentary 1"); // error
    EndTry;

Correct code

    Try
      ServerCode();
    Except

      ErrorText = DetailErrorDescription(ErrorInfo());
      WriteLogEvent(NStr("en = 'Performing an operation'"), EventLogLevel.Error, , ,
         ErrorText);
    EndTry;

    Try
      ServerCode();
    Except

      ErrorText = DetailErrorDescription(ErrorInfo());
      WriteLogEvent(NStr("en = 'Performing an operation'"), EventLogLevel.Error, , ,
         ErrorText);

      Raise;
    EndTry;

Sources

Snippets

Diagnostic ignorance in code

// BSLLS:UsageWriteLogEvent-off
// BSLLS:UsageWriteLogEvent-on

Parameter for config

"UsageWriteLogEvent": false