C#:
using System;
using System.IO;
using Newtonsoft.Json;
namespace Oxide.Plugins
{
[Info("Copylog", "Soller", "1.0.2")]
[Description("Copy console log file")]
public class Copylog : RustPlugin
{
private void CopyLogFile()
{
string logFilePath = @"console.log";
string currentTime = DateTime.Now.ToString("dd.MM.yyyy - HH'h 'mm'm 'ss's'");
string destinationDirectory = Path.Combine("oxide", "logs", "Console_log");
string destinationPath = Path.Combine(destinationDirectory, $"console_{currentTime}.log");
try
{
if (!Directory.Exists(destinationDirectory))
{
Directory.CreateDirectory(destinationDirectory);
}
File.Copy(logFilePath, destinationPath, true);
PrintWarning($"File {logFilePath} copied successfully to {destinationPath}");
}
catch (Exception ex)
{
PrintError($"An error occurred while copying the file: {ex.Message}");
}
}
[ConsoleCommand("copylog")]
private void CopyFileCommand(ConsoleSystem.Arg arg)
{
if (arg.Connection != null && arg.Connection.authLevel < 2)
{
arg.ReplyWith("You need to be an admin to use this command.");
return;
}
CopyLogFile();
}
}
}