You are viewing a potentially older version of this package. View all versions.
tarbaby-DiscordLogSync-1.0.0 icon

DiscordLogSync

Pipes all BepInEx and Unity server logs to a Discord webhook in near-real-time, with buffering and crash-recovery

Date uploaded 3 months ago
Version 1.0.0
Download link tarbaby-DiscordLogSync-1.0.0.zip
Downloads 44
Dependency string tarbaby-DiscordLogSync-1.0.0

This mod requires the following mods to function

denikson-BepInExPack_Valheim-5.4.2333 icon
denikson-BepInExPack_Valheim

BepInEx pack for Valheim. Preconfigured with the correct entry point for mods and preferred defaults for the community.

Preferred version: 5.4.2333

README

DiscordLogger — Valheim BepInEx Mod

Pipes all BepInEx log output to a Discord webhook in near-real-time, with local buffering so no lines are lost on unexpected process death.


How It Works

Every log line
      │
      ▼
BepInEx/DiscordLogBuffer.txt   ← flushed to disk immediately, every line
      │
      ▼ (every N seconds, background thread)
Discord Webhook POST
      │
      ├─ read from front of buffer
      ├─── success (200) → remove read lines from front.
      └─── failure (500) → leave buffer, retry next tick

On next startup:
  buffer file exists? → send as "recovered from crash" → delete → begin fresh

Build

Requirements: .NET SDK with netstandard2.1 support (i.e. .NET Core 3.0+ or .NET 5+ SDK), dotnet CLI, Valheim dedicated server + BepInEx installed.

Targets netstandard2.1, which runs on Unity's Mono 6.4+ runtime. Not compatible with plain .NET Framework 4.7.2.

The .csproj assumes the default Linux Steam dedicated server path:

~/.steam/steam/steamapps/common/Valheim dedicated server

Edit the <ValheimDir> property if your path differs.

dotnet build -c Release

Output: bin/Release/netstandard2.1/DiscordLogger.dll


Install

  1. Copy DiscordLogger.dll into BepInEx/plugins/
  2. Launch the game once to generate the config file
  3. Open BepInEx/config/com.byawn.DiscordLogSync.cfg
  4. Set your webhook URL:
[Discord]
WebhookUrl = https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN
SendIntervalSeconds = 3
MaxMessageChars = 1800
  1. Restart

Config Options

Key Default Description
WebhookUrl (empty) Required. Discord webhook URL.
SendIntervalSeconds 3 How often to flush buffer to Discord. Minimum 2.
MaxMessageChars 1800 Characters per embed.

Buffer File

BepInEx/DiscordLogBuffer.txt

  • Created fresh each run
  • Every line flushed to disk immediately (no in-memory buffering)
  • If the file exists on startup → previous run crashed → contents sent as recovery message
  • Treated like a FIFO so as to fit inside Discord message size limits.

Discord Message Colors [UNUSED FEATURE?]

Situation Color
Contains [Fatal] or [Error] 🔴 Red
Contains [Warning] 🟠 Orange
Recovery (crash) 🟣 Purple
Normal 🔵 Blue

CHANGELOG

1.0.4

  • Updated BepInEx dependency to 5.4.2333

1.0.3

  • Windows compatibility for RawStdout source — the fd-level pipe intercept now works on Windows via P/Invoke into ucrtbase.dll (_dup, _dup2, _pipe, _read, _write, _close). This works because ucrtbase.dll is the Universal CRT shared across Unity's native engine and all managed code in the process.

    Silent failure mode: If the Unity build were statically linked against the CRT (extremely unlikely on modern Unity 6), _dup2 would still succeed but Unity's native writes would go to a separate fd table, never passing through the pipe. The plugin would start cleanly and BepInEx-sourced lines would still appear in Discord — but world save lines and other native stdout output would be silently absent. You would only notice by their absence. On Linux this concern does not apply.

1.0.2

  • Add configurable Source setting: BepInEx (default), Console, or RawStdout
  • BepInEx — original ILogListener approach, unchanged
  • Console — intercepts managed Console.Out via Console.SetOut()
  • RawStdout — experimental, Linux only; intercepts stdout at the OS file descriptor level using pipe()+dup2(), capturing world saves, ZDO counts, and all native stdout writes that bypass BepInEx entirely. Falls back to BepInEx source on init failure.
  • Fix recovery message title to include server name and timestamp
  • Fix shutdown message to use consistent em-dash formatting

1.0.1

  • Add server name and timestamp to the message title
  • Don't double up timestamps in the message content
  • Show log event source and level

1.0.0

  • Initial release
  • Pipes all BepInEx and Unity logs to a Discord webhook in near-real-time
  • Local buffer file flushed on every line — nothing lost on unexpected shutdown
  • FIFO queue — oldest logs sent first, catches up automatically after bursts
  • Crash recovery — leftover buffer from previous session sent on next startup flagged as recovered
  • Configurable send interval and max message size