Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont swallow exceptions when there is no message #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ _ReSharper*/
~$*

#NuGet
# packages/
packages/
*.nupkg

#ncrunch
*ncrunch*
*crunch*.local.xml

# visual studio database projects
*.dbmdl
*.dbmdl
6 changes: 3 additions & 3 deletions ConsoleRunner/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
/>
<target name="graylog"
xsi:type="graylog"
hostip="192.168.1.12"
hostport="12201"
Facility="console-runner"
hostip="10.254.3.31"
hostport="12202"
Facility=""
/>
</targets>

Expand Down
146 changes: 74 additions & 72 deletions ConsoleRunner/Gelf4NLog.ConsoleRunner.csproj
Original file line number Diff line number Diff line change
@@ -1,79 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A6E29782-E22C-4B2A-938F-5A4C8A1BC117}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Gelf4NLog.ConsoleRunner</RootNamespace>
<AssemblyName>Gelf4NLog.ConsoleRunner</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Gelf4NLog.Target, Version=1.0.0.2, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Gelf4NLog.Target.1.0.0.2\lib\net40\Gelf4NLog.Target.dll</HintPath>
</Reference>
<Reference Include="LumenWorks.Framework.IO">
<HintPath>..\packages\LumenWorks.Framework.IO\LumenWorks.Framework.IO.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="comics.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A6E29782-E22C-4B2A-938F-5A4C8A1BC117}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Gelf4NLog.ConsoleRunner</RootNamespace>
<AssemblyName>Gelf4NLog.ConsoleRunner</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="LumenWorks.Framework.IO">
<HintPath>..\packages\LumenWorks.Framework.IO\LumenWorks.Framework.IO.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="comics.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Target\Gelf4NLog.Target.csproj">
<Project>{8a614770-aec9-42ad-87ba-ccd53f880a55}</Project>
<Name>Gelf4NLog.Target</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
-->
</Project>
99 changes: 49 additions & 50 deletions ConsoleRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,53 @@
using LumenWorks.Framework.IO.Csv;
using NLog;

namespace Gelf4NLog.ConsoleRunner
{
class Program
{
private static readonly Random Random = new Random();
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

static void Main()
{
while (true)
{
var comic = GetNextComic();

var eventInfo = new LogEventInfo
{
Message = comic.Title,
Level = LogLevel.Info,
};
eventInfo.Properties.Add("Publisher", comic.Publisher);
eventInfo.Properties.Add("ReleaseDate", comic.ReleaseDate);

Logger.Log(eventInfo);

Thread.Sleep(1000);
}
}

private static Comic GetNextComic()
{
var nextComicIndex = Random.Next(1, 400);

using (var csv = new CsvReader(new StreamReader("comics.csv"), false))
{
csv.MoveTo(nextComicIndex);
return new Comic
{
Title = csv[2],
Publisher = csv[1],
ReleaseDate = csv[0]
};
}
}
}

class Comic
{
public string Title { get; set; }
public string ReleaseDate { get; set; }
public string Publisher { get; set; }
}
namespace Gelf4NLog.ConsoleRunner {
class Program {
private static readonly Random Random = new Random();
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

static void Main() {
Logger.LogException(LogLevel.Error, "a specially crafted error just for you", new InvalidOperationException("Testy error"));
Logger.Log(new LogEventInfo {
Level = LogLevel.Error,
Message = null,
Exception = new InvalidOperationException("And here it is"),
});
Logger.Info("and now we're done");
return;
while (true) {
var comic = GetNextComic();

var eventInfo = new LogEventInfo {
Message = comic.Title,
Level = LogLevel.Info,
};
eventInfo.Properties.Add("Publisher", comic.Publisher);
eventInfo.Properties.Add("ReleaseDate", comic.ReleaseDate);

Logger.Log(eventInfo);

Thread.Sleep(1000);
}
}

private static Comic GetNextComic() {
var nextComicIndex = Random.Next(1, 400);

using (var csv = new CsvReader(new StreamReader("comics.csv"), false)) {
csv.MoveTo(nextComicIndex);
return new Comic {
Title = csv[2],
Publisher = csv[1],
ReleaseDate = csv[0]
};
}
}
}

class Comic {
public string Title { get; set; }
public string ReleaseDate { get; set; }
public string Publisher { get; set; }
}
}
2 changes: 1 addition & 1 deletion Target/GelfConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public JObject GetGelfJson(LogEventInfo logEventInfo, string facility)
{
//Retrieve the formatted message from LogEventInfo
var logEventMessage = logEventInfo.FormattedMessage;
if (logEventMessage == null) return null;
if (logEventMessage == null && logEventInfo.Exception == null) return null;

//If we are dealing with an exception, pass exception properties to LogEventInfo properties
if (logEventInfo.Exception != null)
Expand Down
Loading