Skip to content

Commit

Permalink
fix: version log files (closes #315) (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwesterhausen authored Nov 22, 2024
1 parent d72ccd3 commit 75fb1a4
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
43 changes: 39 additions & 4 deletions DiscordConnector/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,44 @@ private void InitializeLogFile()
{
if (File.Exists(_logFilePath))
{
string oldLogFilePath = $"{_logFilePath}.old";
File.Move(_logFilePath, oldLogFilePath);
_logger.LogInfo($"Existing log file moved to {oldLogFilePath}");
// versions old logs, like log.1 log.2 (up to 5)
for (int i = 5; i > 1; i--)
{
string oldLogFilePath = $"{_logFilePath}.{i}";
string newLogFilePath = $"{_logFilePath}.{i - 1}";
if (File.Exists(oldLogFilePath))
{
try
{
File.Delete(oldLogFilePath);
}
catch (System.Exception ex)
{
_logger.LogError($"Error deleting old log file: {ex.Message}");
}
}
if (File.Exists(newLogFilePath))
{
try
{
File.Move(newLogFilePath, oldLogFilePath);
}
catch (System.Exception ex)
{
_logger.LogError($"Error moving log file: {ex.Message}");
}
}
}
// move current log to log.1, which gets moved if exists in the loop above
try
{
File.Move(_logFilePath, $"{_logFilePath}.1");
}
catch (System.Exception ex)
{
_logger.LogError($"Error moving log file: {ex.Message}");
}
_logger.LogInfo("Existing log files versioned.");
}
}

Expand All @@ -38,7 +73,7 @@ private void InitializeLogFile()
/// <param name="severity">The severity to include, e.g. "WARN" or "DEBUG"</param>
/// <param name="message">The message to log</param>
/// <returns>
/// This will attempt to write to the log file. If it fails, it will log an error to the BepInEx logger.
/// /// This will attempt to write to the log file. If it fails, it will log an error to the BepInEx logger.
///
/// Nothing is returned from this method.
/// </returns>
Expand Down
2 changes: 1 addition & 1 deletion DiscordConnector/PluginInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static class PluginInfo
{
public const string PLUGIN_ID = "games.nwest.valheim.discordconnector";
public const string PLUGIN_NAME = "Valheim Discord Connector";
public const string PLUGIN_VERSION = "2.3.2";
public const string PLUGIN_VERSION = "2.3.3";
public const string PLUGIN_REPO_SHORT = "github: nwesterhausen/valheim-discordconnector";
public const string PLUGIN_AUTHOR = "Nicholas Westerhausen";
public const string SHORT_PLUGIN_ID = "discordconnector";
Expand Down
6 changes: 6 additions & 0 deletions Metadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ See the [current roadmap](https://github.com/nwesterhausen/valheim-discordconnec

## Abridged Changelog

### Version 2.3.3

Fixes

- Can't start plugin when the old log exists in some situations

### Version 2.3.2

Built against the latest version of Valheim (0.219.14, the Bog Witch update).
Expand Down
2 changes: 1 addition & 1 deletion Metadata/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "DiscordConnector",
"version_number": "2.3.2",
"version_number": "2.3.3",
"website_url": "https://discord-connector.valheim.games.nwest.one/",
"description": "Connects your Valheim server to a Discord webhook. Works for both dedicated and client-hosted servers.",
"dependencies": [
Expand Down
2 changes: 1 addition & 1 deletion Metadata/thunderstore.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ schemaVersion = "0.0.1"
[package]
namespace = "nwesterhausen"
name = "DiscordConnector"
versionNumber = "2.3.2"
versionNumber = "2.3.3"
description = "Connects your Valheim server to a Discord webhook. Works for both dedicated and client-hosted servers."
websiteUrl = "https://discord-connector.valheim.games.nwest.one/"
containsNsfwContent = false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![CodeQL](https://github.com/nwesterhausen/valheim-discordconnector/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/nwesterhausen/valheim-discordconnector/actions/workflows/codeql-analysis.yml)
[![Build](https://github.com/nwesterhausen/valheim-discordconnector/actions/workflows/dotnet.yml/badge.svg)](https://github.com/nwesterhausen/valheim-discordconnector/actions/workflows/dotnet.yml)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/nwesterhausen/valheim-discordconnector?label=Github%20Release&style=flat&labelColor=%2332393F)](https://github.com/nwesterhausen/valheim-discordconnector/releases/latest)
[![Thunderstore.io](https://img.shields.io/badge/Thunderstore.io-2.3.2-%23375a7f?style=flat&labelColor=%2332393F)](https://valheim.thunderstore.io/package/nwesterhausen/DiscordConnector/)
[![Thunderstore.io](https://img.shields.io/badge/Thunderstore.io-2.3.3-%23375a7f?style=flat&labelColor=%2332393F)](https://valheim.thunderstore.io/package/nwesterhausen/DiscordConnector/)
[![NexusMods](https://img.shields.io/badge/NexusMods-2.1.14-%23D98F40?style=flat&labelColor=%2332393F)](https://www.nexusmods.com/valheim/mods/1551/)
![Built against Valheim version](https://img.shields.io/badge/Built_against_Valheim-0.219.14-purple?style=flat&labelColor=%2332393F)

Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

A full changelog of changes, dating all the way back to the first release.

## Version 2.3.3

Fixes

- Can't start plugin when the old log exists in some situations

## Version 2.3.2

Built against the latest version of Valheim (0.219.14, the Bog Witch update).
Expand Down

0 comments on commit 75fb1a4

Please sign in to comment.