mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-15 19:22:19 +08:00
更新NLog、打包时包含pdb、添加Sentry
This commit is contained in:
parent
d5f248de78
commit
6618cc89a5
|
@ -10,6 +10,9 @@ indent_size = 4
|
|||
charset = utf-8
|
||||
insert_final_newline = true
|
||||
|
||||
[NLog.{Debug,Release}.config]
|
||||
indent_size = 2
|
||||
|
||||
[*.cs]
|
||||
|
||||
#Core editorconfig formatting - indentation
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Autofac" Version="4.9.4" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="NLog" Version="4.5.10" />
|
||||
<PackageReference Include="NLog" Version="4.7.6" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BililiveRecorder.FlvProcessor\BililiveRecorder.FlvProcessor.csproj" />
|
||||
|
|
|
@ -269,7 +269,7 @@ namespace BililiveRecorder.Core
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Log(RoomId, LogLevel.Error, "在尝试停止录制时发生错误,请检查网络连接是否稳定", ex);
|
||||
logger.Log(RoomId, LogLevel.Warn, "在尝试停止录制时发生错误,请检查网络连接是否稳定", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -388,7 +388,7 @@ namespace BililiveRecorder.Core
|
|||
catch (Exception ex)
|
||||
{
|
||||
_CleanupFlvRequest();
|
||||
logger.Log(RoomId, LogLevel.Warn, "启动直播流下载出错。" + (_retry ? "将重试启动。" : ""), ex);
|
||||
logger.Log(RoomId, LogLevel.Error, "启动直播流下载出错。" + (_retry ? "将重试启动。" : ""), ex);
|
||||
if (_retry)
|
||||
{
|
||||
StreamMonitor.Check(TriggerType.HttpApiRecheck, (int)_config.TimingStreamRetry);
|
||||
|
|
|
@ -246,7 +246,7 @@ namespace BililiveRecorder.Core
|
|||
catch (Exception ex)
|
||||
{
|
||||
dmError = ex;
|
||||
logger.Log(Roomid, LogLevel.Error, "连接弹幕服务器错误", ex);
|
||||
logger.Log(Roomid, LogLevel.Warn, "连接弹幕服务器错误", ex);
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsDanmakuConnected)));
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac" Version="4.9.4" />
|
||||
<PackageReference Include="NLog" Version="4.5.10" />
|
||||
<PackageReference Include="NLog" Version="4.7.6" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>cd $(SolutionDir)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using NLog;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
@ -82,8 +82,6 @@ namespace BililiveRecorder.FlvProcessor
|
|||
fs.Close();
|
||||
}
|
||||
Tags.Clear();
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
@ -28,11 +29,17 @@ namespace BililiveRecorder.WPF
|
|||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("BILILIVE_RECORDER_DISABLE_UPDATE"))) { return; }
|
||||
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("BILILIVE_RECORDER_DISABLE_UPDATE"))
|
||||
|| File.Exists("BILILIVE_RECORDER_DISABLE_UPDATE"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var envPath = Environment.GetEnvironmentVariable("BILILIVE_RECORDER_OVERWRITE_UPDATE");
|
||||
string serverUrl = @"https://soft.danmuji.org/BililiveRecorder/";
|
||||
var serverUrl = @"https://soft.danmuji.org/BililiveRecorder/";
|
||||
if (!string.IsNullOrWhiteSpace(envPath)) { serverUrl = envPath; }
|
||||
using (UpdateManager manager = new UpdateManager(urlOrPath: serverUrl))
|
||||
logger.Debug("Checking updates.");
|
||||
using (var manager = new UpdateManager(urlOrPath: serverUrl))
|
||||
{
|
||||
var update = await manager.CheckForUpdate();
|
||||
if (update.CurrentlyInstalledVersion == null)
|
||||
|
@ -72,7 +79,7 @@ namespace BililiveRecorder.WPF
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "检查更新时出错,如持续出错请联系开发者 rec@danmuji.org");
|
||||
logger.Warn(ex, "检查更新时出错,如持续出错请联系开发者 rec@danmuji.org");
|
||||
}
|
||||
|
||||
_ = Task.Run(async () => { await Task.Delay(TimeSpan.FromDays(1)); await RunCheckUpdate(); });
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>BililiveRecorder.WPF.App</StartupObject>
|
||||
<StartupObject>BililiveRecorder.WPF.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<GenerateManifests>false</GenerateManifests>
|
||||
|
@ -128,6 +128,7 @@
|
|||
<Compile Include="Converters\PercentageToColorBrushConverter.cs" />
|
||||
<Compile Include="Converters\RoomListInterceptConverter.cs" />
|
||||
<Compile Include="CommandLineOption.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="SingleInstance.cs" />
|
||||
<Page Include="Controls\AddRoomCard.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
|
@ -237,7 +238,7 @@
|
|||
<Content Include="NLog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="Nlog.Release.config" />
|
||||
<None Include="NLog.Release.config" />
|
||||
<None Include="NLog.Debug.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -269,14 +270,23 @@
|
|||
<PackageReference Include="Newtonsoft.Json">
|
||||
<Version>11.0.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NLog">
|
||||
<Version>4.7.6</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NLog.Config">
|
||||
<Version>4.5.10</Version>
|
||||
<Version>4.7.6</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NuGet.CommandLine">
|
||||
<Version>4.7.1</Version>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Sentry">
|
||||
<Version>2.1.8</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Sentry.NLog">
|
||||
<Version>2.1.8</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="squirrel.windows">
|
||||
<Version>2.0.1</Version>
|
||||
</PackageReference>
|
||||
|
@ -292,7 +302,7 @@
|
|||
<PropertyGroup>
|
||||
<PreBuildEvent>cd $(SolutionDir)
|
||||
powershell -ExecutionPolicy Bypass -File .\CI\patch_buildinfo.ps1 WPF
|
||||
copy /y .\BililiveRecorder.WPF\Nlog.$(ConfigurationName).config .\BililiveRecorder.WPF\NLog.config</PreBuildEvent>
|
||||
copy /y .\BililiveRecorder.WPF\NLog.$(ConfigurationName).config .\BililiveRecorder.WPF\NLog.config</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SquirrelBuildTarget Condition=" '$(SquirrelBuildTarget)' == '' ">.\SquirrelRelease</SquirrelBuildTarget>
|
||||
|
|
|
@ -12,6 +12,6 @@
|
|||
<language>zh-CN</language>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="*.*" target="lib\net45\" exclude="*.pdb;*.nupkg;*.vshost.*"/>
|
||||
<file src="*.*" target="lib\net45\" exclude="*.nupkg;*.vshost.*"/>
|
||||
</files>
|
||||
</package>
|
|
@ -1,36 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
|
||||
autoReload="true"
|
||||
throwExceptions="false"
|
||||
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
|
||||
|
||||
<!-- optional, add some variables
|
||||
https://github.com/nlog/NLog/wiki/Configuration-file#variables
|
||||
-->
|
||||
<variable name="myvar" value="myvalue"/>
|
||||
|
||||
<!--
|
||||
See https://github.com/nlog/nlog/wiki/Configuration-file
|
||||
for information on customizing logging rules and outputs.
|
||||
-->
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true" throwExceptions="false" throwConfigExceptions="true" internalLogLevel="Off">
|
||||
<extensions>
|
||||
<add assembly="Sentry.NLog"/>
|
||||
</extensions>
|
||||
<targets>
|
||||
<target name="WPFLogger" xsi:type="MethodCall" className="BililiveRecorder.WPF.Models.LogModel, BililiveRecorder.WPF" methodName="AddLog">
|
||||
<parameter layout="[${date:format=HH\:mm\:ss}] ${uppercase:${level}} ${event-properties:item=roomid} ${message} ${exception:format=Message}" />
|
||||
<parameter layout="[${date:format=HH\:mm\:ss}] ${level:upperCase=true} ${event-properties:item=roomid} ${message} ${exception:format=Message}" />
|
||||
</target>
|
||||
|
||||
<target name="file" xsi:type="File"
|
||||
encoding="utf-8"
|
||||
lineEnding="CRLF"
|
||||
fileName="log.txt"
|
||||
maxArchiveFiles="15"
|
||||
archiveFileName="log_archive.{#}.txt"
|
||||
archiveNumbering="Date"
|
||||
archiveEvery="Day"
|
||||
archiveDateFormat="yyyyMMdd">
|
||||
<target name="file" xsi:type="File" encoding="utf-8" lineEnding="CRLF" fileName="logs/log.txt"
|
||||
maxArchiveFiles="15" archiveFileName="logs/log_archive.{#}.txt" archiveNumbering="Date"
|
||||
archiveEvery="Day" archiveDateFormat="yyyyMMdd">
|
||||
<layout xsi:type="JsonLayout">
|
||||
<attribute name='time' layout='${longdate}' />
|
||||
<attribute name='time' layout='${longdate}'/>
|
||||
<attribute name='level' layout='${level:upperCase=true}'/>
|
||||
<attribute name='pid' layout='${processid}'/>
|
||||
<attribute name='logger' layout='${logger}'/>
|
||||
|
@ -45,27 +27,16 @@
|
|||
</attribute>
|
||||
</layout>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
add your targets here
|
||||
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
|
||||
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
|
||||
-->
|
||||
|
||||
<!--
|
||||
Write events to a file with the date in the filename.
|
||||
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
|
||||
layout="${longdate} ${uppercase:${level}} ${message}" />
|
||||
-->
|
||||
<target xsi:type="Sentry" name="sentry" layout="${message}"
|
||||
breadcrumbLayout="${event-properties:item=roomid} ${message}"
|
||||
minimumBreadcrumbLevel="Debug" minimumEventLevel="Error">
|
||||
<options initializeSdk="false"/>
|
||||
<tag name="logger" layout="${logger}" />
|
||||
</target>
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<!-- add your logging rules here -->
|
||||
<logger name="*" writeTo="sentry"/>
|
||||
<logger name="*" minlevel="Trace" writeTo="WPFLogger"/>
|
||||
<logger name="*" minlevel="Trace" writeTo="file"/>
|
||||
<!--
|
||||
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
|
||||
<logger name="*" minlevel="Debug" writeTo="f" />
|
||||
-->
|
||||
</rules>
|
||||
</nlog>
|
||||
|
|
|
@ -1,25 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
|
||||
autoReload="true"
|
||||
throwExceptions="false"
|
||||
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true" throwExceptions="false" throwConfigExceptions="true" internalLogLevel="Off">
|
||||
<extensions>
|
||||
<add assembly="Sentry.NLog"/>
|
||||
</extensions>
|
||||
<targets>
|
||||
<target name="WPFLogger" xsi:type="MethodCall" className="BililiveRecorder.WPF.Models.LogModel, BililiveRecorder.WPF" methodName="AddLog">
|
||||
<parameter layout="[${date:format=HH\:mm\:ss}] ${uppercase:${level}} ${event-properties:item=roomid} ${message} ${exception:format=Message}" />
|
||||
<parameter layout="[${date:format=HH\:mm\:ss}] ${level:upperCase=true} ${event-properties:item=roomid} ${message} ${exception:format=Message}" />
|
||||
</target>
|
||||
<target name="file" xsi:type="File"
|
||||
encoding="utf-8"
|
||||
lineEnding="CRLF"
|
||||
fileName="log.txt"
|
||||
maxArchiveFiles="15"
|
||||
archiveFileName="log_archive.{#}.txt"
|
||||
archiveNumbering="Date"
|
||||
archiveEvery="Day"
|
||||
archiveDateFormat="yyyyMMdd">
|
||||
<target name="file" xsi:type="File" encoding="utf-8" lineEnding="CRLF" fileName="logs/log.txt"
|
||||
maxArchiveFiles="15" archiveFileName="logs/log_archive.{#}.txt" archiveNumbering="Date"
|
||||
archiveEvery="Day" archiveDateFormat="yyyyMMdd">
|
||||
<layout xsi:type="JsonLayout">
|
||||
<attribute name='time' layout='${longdate}' />
|
||||
<attribute name='time' layout='${longdate}'/>
|
||||
<attribute name='level' layout='${level:upperCase=true}'/>
|
||||
<attribute name='pid' layout='${processid}'/>
|
||||
<attribute name='logger' layout='${logger}'/>
|
||||
|
@ -34,8 +27,15 @@
|
|||
</attribute>
|
||||
</layout>
|
||||
</target>
|
||||
<target xsi:type="Sentry" name="sentry" layout="${message}"
|
||||
breadcrumbLayout="${event-properties:item=roomid} ${message}"
|
||||
minimumBreadcrumbLevel="Debug" minimumEventLevel="Error">
|
||||
<options initializeSdk="false"/>
|
||||
<tag name="logger" layout="${logger}" />
|
||||
</target>
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" writeTo="sentry"/>
|
||||
<logger name="*" minlevel="Info" writeTo="WPFLogger"/>
|
||||
<logger name="*" minlevel="Debug" writeTo="file"/>
|
||||
</rules>
|
||||
|
|
|
@ -75,6 +75,18 @@
|
|||
</ui:NumberBox>
|
||||
</ui:SimpleStackPanel>
|
||||
</GroupBox>
|
||||
<GroupBox Header="手动崩溃">
|
||||
<Button Content="Crash EVERTHING !!1">
|
||||
<ui:FlyoutService.Flyout>
|
||||
<ui:Flyout>
|
||||
<StackPanel>
|
||||
<TextBlock Text="Are you sure about that?" Margin="0,0,0,12" />
|
||||
<Button Click="Crash_Click" Content="Yes" />
|
||||
</StackPanel>
|
||||
</ui:Flyout>
|
||||
</ui:FlyoutService.Flyout>
|
||||
</Button>
|
||||
</GroupBox>
|
||||
</ui:SimpleStackPanel>
|
||||
</ScrollViewer>
|
||||
</ui:Page>
|
||||
|
|
|
@ -1,17 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace BililiveRecorder.WPF.Pages
|
||||
{
|
||||
|
@ -24,5 +13,18 @@ namespace BililiveRecorder.WPF.Pages
|
|||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Crash_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
throw new TestException("test crash triggered");
|
||||
}
|
||||
|
||||
public class TestException : Exception
|
||||
{
|
||||
public TestException() { }
|
||||
public TestException(string message) : base(message) { }
|
||||
public TestException(string message, Exception innerException) : base(message, innerException) { }
|
||||
protected TestException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
67
BililiveRecorder.WPF/Program.cs
Normal file
67
BililiveRecorder.WPF/Program.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Security;
|
||||
using System.Windows.Threading;
|
||||
using NLog;
|
||||
using Sentry;
|
||||
|
||||
namespace BililiveRecorder.WPF
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
[STAThread]
|
||||
public static int Main()
|
||||
{
|
||||
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
using (SentrySdk.Init(o =>
|
||||
{
|
||||
if (!File.Exists("BILILIVE_RECORDER_DISABLE_SENTRY")
|
||||
&& string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("BILILIVE_RECORDER_DISABLE_SENTRY")))
|
||||
{
|
||||
o.Dsn = new Dsn("https://55afa848ac49493a80cc4366b34e9552@o210546.ingest.sentry.io/5556540");
|
||||
}
|
||||
|
||||
var v = typeof(Program).Assembly.GetName().Version;
|
||||
if (v.Major != 0)
|
||||
{
|
||||
o.Release = "BililiveRecorder@" + v.ToString();
|
||||
}
|
||||
o.DisableAppDomainUnhandledExceptionCapture();
|
||||
o.AddExceptionFilterForType<System.Net.Http.HttpRequestException>();
|
||||
}))
|
||||
{
|
||||
var app = new App();
|
||||
app.InitializeComponent();
|
||||
app.DispatcherUnhandledException += App_DispatcherUnhandledException;
|
||||
return app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
|
||||
{
|
||||
LogManager.Flush();
|
||||
LogManager.Shutdown();
|
||||
}
|
||||
|
||||
[HandleProcessCorruptedStateExceptions, SecurityCritical]
|
||||
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
if (e.ExceptionObject is Exception ex)
|
||||
{
|
||||
logger.Fatal(ex, "Unhandled exception from Application.UnhandledException");
|
||||
LogManager.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
[HandleProcessCorruptedStateExceptions, SecurityCritical]
|
||||
private static void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
logger.Fatal(e.Exception, "Unhandled exception from AppDomain.DispatcherUnhandledException");
|
||||
LogManager.Flush();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user